local Increase=script.Parent.IncreaseBeans.Touched
local IncreaseEnd=script.Parent.IncreaseBeans.TouchEnded
function AddBeans(hit)
cool=true
if hit.Parent:FindFirstChild('Humanoid') then
script.Parent.IncreaseBeans.CanCollide=false
local Player=game.Players:GetPlayerFromCharacter(hit.Parent)
local Beans=Player.leaderstats.Beans
while task.wait(2) do
Beans.Value+=2
task.wait(2)
cool=false
end
end
end
Increase:Connect(AddBeans)```but its adding to fast
#im making a zone to increase Beans Value
155 messages · Page 1 of 1 (latest)
wt
** You are now Level 1! **
** You are now Level 8! **
you need to check whether the player is already in the zone
so what should i do for that its my first time doing a zone for a game that im helping
what is a zone anyway?
to increase the Beans Value
rectangle?
ye its a rectangle
its sad that i can do a screenshot
but i did it in the roblox studio instead
local check:boolean = false;
-- touched
if not check then
cool = true;
-- your code
end;
-- touchended
if cool then
cool = false;
end;
which zoneplus?
local Increase=script.Parent.IncreaseBeans.Touched
local IncreaseEnd=script.Parent.IncreaseBeans.TouchEnded
function AddBeans(hit)
if cool==false then
cool=true
if hit.Parent:FindFirstChild('Humanoid') then
script.Parent.IncreaseBeans.CanCollide=false
local Player=game.Players:GetPlayerFromCharacter(hit.Parent)
local Beans=Player.leaderstats.Beans
while task.wait(2) do
Beans.Value+=2
task.wait(1)
cool=false
end
end
end
end
Increase:Connect(AddBeans)```
touchended
i tried that and its to confusing
i tried that and it didnt work it was going to fast when i entered the zone
what's it
** You are now Level 2! **
the zone scirpt
it
oh i removed the other task.wait
which other?
After the bean.Value+=2
No, wtf do not used touched for this are you out of your mind 😅
oh you using zone+? pretty easy actually
this code is not Zone+ though 🤔
Well I don’t know how to use it
It’s the IncreaseBean part
K
IF you don't know how to use zone+ they have VERY comprehensive docos here
Documentation for ZonePlus
so put zone+ in your replicated storage so we'll go from there
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ZonePlus = require(ReplicatedStorage.ZonePlus)
right?
so I see the beans are in the player leaderstats
local Beans=Player.leaderstats.Beans
okay easy enough
so zone plus has these cool events to know if a player entered a zone or if left it!
which is super useful!
After I play one more match I’m getting back on
nah, you getting on now, I have only 30 minutes and after that I'm gone 🙂
else you can just ask help to someone else 😄
I edit his code
sadly, your edit was pretty darn bad, but please don't let that stop you from helping, that's how you learn
if you want you can stick along!
awsome alright
K I’m sticking along
was talking to darkside lol, but yah you too
so ofc we need to create the zone first
let me see how you have that one sec
K
Oh okay
Here
the zone is the parent of the script
I know
lol
so pretty straighforward!
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ZonePlus = require(ReplicatedStorage.ZonePlus)
local BeansZone = ZonePlus.new(script.Parent) --> returns a zone
so that's the zone!
So the Zone.Size is equal to the one I have
don't worry about that, zone plus handles that for you
Oh k
oh wait we are doing it from container
Well I’m talking about the part that I have then copy the size then for the Zone.Size is equal to that
so just the container arg
how so?
Vector3.new(100,50,35)
yeah but what is that for 😅 ?
Lao this in the script for the zone in the workspace
correct
It’s for the size of the zone
again, Zone plus handles that for you 🙂
K
you just have to pass it a container
could be a folder, model, or part
sooo! we have our beans zone
if we go to the events section of zone plus https://1foreverhd.github.io/ZonePlus/api/zone/#events
you'll see Zones objects have the playerEntered and playerExited events
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ZonePlus = require(ReplicatedStorage.ZonePlus)
local BeansZone = ZonePlus.new(script.Parent) --> returns a zone
Documentation for ZonePlus
My pc is slow but it’s a gaming pc
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ZonePlus = require(ReplicatedStorage.ZonePlus)
local BeansZone = ZonePlus.new(script.Parent) --> returns a zone
BeansZone.playerEntered:Connect(function(playerThatEntered)
print(playerThatEntered)
end)
BeansZone.playerLeft:Connect(function(playerThatleft)
print(playerThatLeft)
end)
now this is were the hard part comes in
actually giving the coins!
I thought it was Player but it’s the zone
ofc, that's an event of the zone
not the player
lol
again, check docos
^
we need for a way to reward all the players within the zone
since this events open new threads we cannot actually do this
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ZonePlus = require(ReplicatedStorage.ZonePlus)
local BeansZone = ZonePlus.new(script.Parent) --> returns a zone
BeansZone.playerEntered:Connect(function(playerThatEntered)
print(playerThatEntered)
while true do
-- beans here
end
end)
BeansZone.playerLeft:Connect(function(playerThatleft)
print(playerThatLeft)
end)
What do I put for the repstorage
we cannot do that
ZonePlus module
just go back to the top or read on it I'll just finish explaining from here
k
cause 15 min left
so we need a way to safely add beans to all players within the zone! that's actually super straighforward, we want to have a while loop outside the events that loops through every player in the zone and gives it beans
super easy, we can do that like so
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ZonePlus = require(ReplicatedStorage.ZonePlus)
local BeansZone = ZonePlus.new(script.Parent) --> returns a zone
local playersInBeansZone = {}
BeansZone.playerEntered:Connect(function(playerThatEntered)
print(playerThatEntered)
table.insert(playersInBeansZone, playerThatEntered)
end)
BeansZone.playerLeft:Connect(function(playerThatleft)
print(playerThatLeft)
table.remove(playersInBeansZone, playerThatEntered)
end)
while true do
for _, player in playersInBeansZone do
-- rewardLogicHere
end
task.wait(1)
end
and there you have it!
is it supposed to be like that
we use a table to keep track of the players that are within the BeansZone so!
-
When a player enters the bean zone we insert it to a table
-
When a player exits the bean zone we remove it from the table
-
a while loop that'll be looping forever will iterate over all players present in the
playersInBeansZonetable and you would put the reward logic there
😄
it's quite obbvious what the error is there 🙂
if you cannot solve it theeen sadly I cannot do much more for you :D. this explanation is already a lot and you have the implementation here
now only thing left for you is adding the rewarding logic 😉
which you already did! it's just copy pasting
@tawdry wind hope you also found this bit helpful, and as you can see it's a bit cleaner! and more straighforward, even with vanilla spatial queries this would have been rather easy
do not use touch/touchended for this, super unreliable
so how can i put the zone in this side
well, by moving it
lol
move it to that side I guess
cause you coded it, no?
^
all those zones have that script
so you know it has it
if it's not adding beans then you know for a fact that either:
- the zone is not there
- the script is not working correctly
you have a long way to go :D. keep practicing! aight you guys have a lovely night
ok
I already said, touch and touchended were used by HE, not me
oh well then just hammering down on it ig 😄
local ReplicatedStorage=game.ReplicatedStorage
local zoneplus=require(ReplicatedStorage.Zone)
local Worlds=workspace.Worlds
local function newPlayer(plr)
local worldBoost=Instance.new('NumberValue',plr)
worldBoost.Name='Boost'
worldBoost.Value=1
end
local function setupWorldBoost()
for i,world in pairs(Worlds:GetChildren()) do
if (not world:IsA('BasePart')) then
continue
end
local zone=zoneplus.new(world)
zone.playerEntered:Connect(function(plr)
plr.Boost.Value=world.Boost.Value
while task.wait(2) do
plr.leaderstats.Beans.Value+=plr.Boost.Value
end
end)
zone.playerExited:Connect(function(plr)
plr.Boost.Value=1
end)
end
end
setupWorldBoost()
Players.PlayerAdded:Connect(newPlayer)```so smth like that
Oh dear 😅
when i test it its working when i add to lua local function giveCurrency(player) while true do task.wait(2) player.leaderstats.Beans.Value+=2*(player.Boost.Value) if player.leaderstats.Beans.Value==player.Stats.MaxedBeans.Value then end end end