Hi, I want to make a safe zone type of thing and I am using ZonePlus for it. It works perfectly however, it does not change when the player is in it at the start.
Let me explain: The player joins the game and is in lobby. The safe zone covers the entire lobby. What’s supposed to happen is that their steps get changed to “inf”. However, when they spawn in, their steps don’t get changed to that. However when they go out then back in, it works perfectly.
How would I fix this?
can you provide code? I tested this with a zone covering the baseplate spawn and I get triggered “Player Entered” at the start
Local script in StarterGui:
local SafeZones = workspace.SafeZones
local plr = game.Players.LocalPlayer
local ZN = require(game.ReplicatedStorage.Zone)
local steps = plr.PlayerGui:WaitForChild("StepsGUI").Frame.TextLabel
local stagetrans = plr.PlayerGui:WaitForChild("StageTransfer").CurrentStage
local mod = plr.PlayerGui:WaitForChild('StoreSteps')
local data = require(mod)
for _,v in ipairs(workspace.SafeZones:GetChildren()) do
local zone = ZN.new(v)
zone.localPlayerEntered:Connect(function(player)
if player == plr then
steps.Text = "inf"
end
end)
zone.localPlayerExited:Connect(function(player)
if player == plr then
steps.Text = tostring(data[stagetrans.Text])
return
end
end)
end
Plus a video:
Also it breaks when I reset character.
SampleFile.rbxl (71.2 KB)
check output, i did not use a text label to display inf/steps
I did some alterations, i made it a local script as you had it, but inside starterplayer playerscripts
you can see it will work even if you reset char. you will need to make you gui not reset on death for this to work since its a starterplayer script, it will execute only once, on new player.
word of advice though I believe you should make it server sided not sure if you do anything important when steps==0 but it should definitely be handled on server script if its important
**also the way i calc’d steps is pretty poor, i just wrote up something that would work for demonstrations, not recommended to use
I believe the reason it starts breaking is because you constantly keep making zones on death? not sure
you could also make 1 singular folder act as a zone, and not each block
Thank you. This fixed the death problem that I have also I think I may have found the reason why it is not changing it to inf. I think its because theres another script that detects the stage transfer that it is 21 and so its making it that. However wouldn’t this script override it?
the script i wrote up is essentially a duplicate mock up of yours excluding some variables like gui elements and data. so i suppose it would override is that what ur asking
not sure why your zone doesnt work upon spawn maybe its because you have the script in starter gui? maybe its because you construct zones everytime on spawn each time? all i know is, for efficiency you can just construct once and be on your merry way
you should also consider constructing one folder to act as the ultimate zone, so you shouldnt need to get children() and construct smaller zones.
I have mostly all of the local scripts I write in StarterGUI. Also in workspace I keep all the zones in one folder called “SafeZones”. Inside there are 2 zones so far. Also it does not construct zones each time I spawn, however it does spawn 3-4 zone modules in workspace when i hit play, not sure if thats part of the ZonePlus modules or not.
that doesn’t sound good, it shouldnt be spawning zone modules.
it does only if the script is not parented under a gui that has reset on death==false, everytime you respawn, startergui has to be replicated
so essentially instead of doing this:
for _,v in ipairs(SafeZones:GetChildren()) do
local zone = ZN.new(v)
zone.localPlayerEntered:Connect(function(player)
Outside=false
print("inf")
steps=100
end)
zone.localPlayerExited:Connect(function(player)
Outside=true
end)
end
you can do:
local zone = ZN.new(SafeZones)
zone.localPlayerEntered:Connect(function(player)
Outside=false
print("inf")
steps=100
end)
zone.localPlayerExited:Connect(function(player)
Outside=true
end)
1 Like