Speed zone problem


local Zone = require(game.ReplicatedStorage.Zone)
local zone = Zone.new(script.Parent)
plr.Character.Humanoid.WalkSpeed = 25
	plr.Character.Humanoid.WalkSpeed = 15

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


give me the module, ill try to understand the issue

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:


im fine with using getpartsinpart or .touched but im just trying to fix this logic problem

instead of setting the player’s speed, simply add/subtract it upon entry/leaving

your problem is unrelated to the zones itself, but how when you leave a zone the speed is always set to 15

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

nope didn’t work, did the same thing
Screenshot 2024-01-02 at 1.45.31 PM

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

I dont see the issue, isn’t that what you want?

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

I think you’re overthinking this

I believe thats the simplest and most straightforward solution

you literally add 3 lines of code, how is that overthinking it : P

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)

when two zones overlap, say i leave the first one, but im still in the second one, leaving the first one makes it 15

There’s no way to elegantly solve this problem, I’d say just don’t have two zones overlapping.

yes but that would produce the same problem
Screenshot 2024-01-02 at 2.15.03 PM

uh its kinda a sandbox game :sob: i have no power over this

I see - The only other solution I might see is constantly checking if the player is touching either of theese zone parts

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