#im making a zone to increase Beans Value

155 messages · Page 1 of 1 (latest)

echo coral
#
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
#

and im confused on how to make it work

tawdry wind
#

wt

pulsar shardBOT
#

studio** You are now Level 1! **studio

tawdry wind
#

'cool' what is this?

#

if you want to make an increase for entering the zone

pulsar shardBOT
#

studio** You are now Level 8! **studio

tawdry wind
echo coral
#

so what should i do for that its my first time doing a zone for a game that im helping

tawdry wind
#

what is a zone anyway?

echo coral
#

to increase the Beans Value

tawdry wind
echo coral
#

ye its a rectangle

#

its sad that i can do a screenshot

#

but i did it in the roblox studio instead

tawdry wind
#
local check:boolean = false;
-- touched
if not check then
    cool = true;
    -- your code
end;
-- touchended
if cool then
    cool = false;
end;
echo coral
#

k

#

so is that ZonePlus

tawdry wind
#

which zoneplus?

echo coral
#
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)```
echo coral
#

but how can i make it when player leaves

echo coral
#

i tried that and its to confusing

tawdry wind
#

wt

#
IncreaseEnd:Connect(function()
    if cool then
        cool = false;
    end;
end);
echo coral
#

i tried that and it didnt work it was going to fast when i entered the zone

pulsar shardBOT
#

studio** You are now Level 2! **studio

tawdry wind
echo coral
#

the zone scirpt

tawdry wind
echo coral
#

oh i removed the other task.wait

tawdry wind
#

which other?

echo coral
#

After the bean.Value+=2

grizzled coyote
grizzled coyote
grizzled coyote
echo coral
#

Well I don’t know how to use it

grizzled coyote
#

Increase:Connect(AddBeans)
what's this?

#

Increase?

#

OH

#

omg

echo coral
#

It’s the IncreaseBean part

grizzled coyote
#

dude okay no

#

please just erase this and let's start over

echo coral
#

K

grizzled coyote
#

IF you don't know how to use zone+ they have VERY comprehensive docos here

#

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!

echo coral
#

After I play one more match I’m getting back on

grizzled coyote
#

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 😄

echo coral
#

K

#

I’m now getting back on

grizzled coyote
#

if you want you can stick along!

grizzled coyote
echo coral
#

K I’m sticking along

grizzled coyote
#

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

echo coral
#

K

grizzled coyote
#

Oh okay

echo coral
grizzled coyote
#

the zone is the parent of the script

grizzled coyote
#

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!

echo coral
#

So the Zone.Size is equal to the one I have

grizzled coyote
#

don't worry about that, zone plus handles that for you

echo coral
#

Oh k

grizzled coyote
#

oh wait we are doing it from container

echo coral
#

Well I’m talking about the part that I have then copy the size then for the Zone.Size is equal to that

grizzled coyote
#

so just the container arg

echo coral
#

Vector3.new(100,50,35)

grizzled coyote
#

yeah but what is that for 😅 ?

echo coral
grizzled coyote
#

correct

echo coral
#

It’s for the size of the zone

grizzled coyote
#

again, Zone plus handles that for you 🙂

echo coral
#

K

grizzled coyote
#

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
echo coral
#

My pc is slow but it’s a gaming pc

grizzled coyote
#

probably you have an HDD lol

#

should upgrade to an SSD

#

so let's add those

echo coral
#

I wish I got pcie nvme 2

#

K

grizzled coyote
#
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!

echo coral
#

I thought it was Player but it’s the zone

grizzled coyote
#

not the player

#

lol

#

again, check docos

grizzled coyote
#

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)
echo coral
#

What do I put for the repstorage

grizzled coyote
#

we cannot do that

grizzled coyote
#

just go back to the top or read on it I'll just finish explaining from here

echo coral
#

k

grizzled coyote
#

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!

echo coral
#

is it supposed to be like that

grizzled coyote
#

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 playersInBeansZone table and you would put the reward logic there

#

😄

grizzled coyote
#

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

echo coral
#

so how can i put the zone in this side

grizzled coyote
#

lol

#

move it to that side I guess

echo coral
#

how would i know that its there

#

the zone

grizzled coyote
grizzled coyote
#

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

echo coral
#

ok

tawdry wind
grizzled coyote
echo coral
# tawdry wind I already said, touch and touchended were used by HE, not me
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
echo coral
#

at least its working

#

when i did test it the Beans was being multiplied

echo coral
# grizzled coyote 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