local Zone = require(game.ReplicatedStorage.Zone)
local zone = Zone.new(script.Parent)
zone.playerEntered:Connect(function(plr)
plr.Character.Humanoid.WalkSpeed = 25
end)
zone.playerExited:Connect(function(plr)
plr.Character.Humanoid.WalkSpeed = 15
end)
i know this si a simple problem, but im not sure how to solve it, this works perfectly with one zone, but if theres zones overlapping each other, the player could turn into 15 when they leave and enter at the same time, please help
the module work like .touched, its just checking if player entered, but the real problem is the logic, when two zones overlap, say i leave the first one, but im still in the second one, leaving the first one makes it 15
but if you want it:
yeah wouldn’t it be the same? say player goes in the first zone, 30, goes between the first zone and the second, 30, leaves the first one but still is in the second one, 30-15
just try it, instead of doing =25, do += 10 (and -=10 for leaving)
going between the 1st and the second should boost that up to 45
unless if you want all the zones to have it be 30, in which case you worded this weirdly, but simply store all the zones the player is currently in in a table, then check if the table is empty
this is the logic, you see when player first enters zone 1, works perfectly fine, between them? totally fine, but when the player enters zone 2, they already been in zone 2 so the player do not get any additional speed, instead, it gets -15 for zone 2
Can you explain what you’re trying to achieve again? Since from what I can infer, the zones are supposed to give extra speed, so this should be correct (you should have 15 speed, 30 in zone 1, 30 in zone 2, 45 if in both zones)
okay, the zones are supposed to get 30 when im in them. it works great with one, it tracks player going in and going out, however, the script sets it to 15 when i am in the second zone (like the graph), when i am supposed to have 30, zone gives 30, no zone 15
oh, so the zones aren’t supposed to be a powerup, but more like a “if your in here its always 30”
I see
well then, simply have a variable which stores how much zones the player is in, and add 1 when entering and remove 1 when leaving. If the variable is greator then 0, set the speed to 30, else set to 15. This if statement should happen whenever player enters or leaves a zone
How about you implement some sort of “is player in zone” variable? -
It would allow you to have a while loop running which just checks if that variable is true and then sets the speed to 30 and if it’s false sets the speed to 15 (atleast if you do not want the zones to stack)
I see two solutions to this, firstly, the one I just described (which I swear it isn’t complicated at all ;-; )
secondly, just group/union all of the speed zone parts, zoneplus takes a non-basepart instance, so that should work
actually nvm depending on how zones are added both could be simpler
yeah i tried something like this with a loop and a getpartsinpart, but i have no way of setting the walk speed when the player is not there, only when the player is there, like this:
while true do
local hit = workspace:GetPartsInPart(script.Parent)
for i, v in pairs(hit) do
if v.parent.humanoid then
--speed stuff
end
wait(0.5)
end