I’m creating an invisible zone that affects the player’s walkspeed. I want it to only fire when the player enters or leaves the zone, ignoring any actions within the zone. I have a script that increases the localplayers walkspeed by 15 when they jump. However, if they jump inside the zone, I want it to add 15 to their current walkspeed instead of overriding it to the zone’s default of 20.
When the player jumps within the zone, it overrides their walkspeed and sets them back to the set zone walkspeed.
I tried adding an if statement that checks if the player has the “WalkspeedRegion” child and returns if so, but the TouchEnded and Touched events still fire regardless.
local original_speed = 16
local new_speed = 20
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") and not hit.Parent:FindFirstChild("WalkspeedRegion") then
local x = Instance.new("BoolValue", hit.Parent);
x.Name = "WalkspeedRegion"
hit.Parent.Humanoid.WalkSpeed = new_speed
end
end)
script.Parent.TouchEnded:Connect(function(hit)
if hit.Parent:FindFirstChild("WalkspeedRegion") and hit.Parent:FindFirstChild("Humanoid") then
hit.Parent.WalkspeedRegion:Destroy()
hit.Parent.Humanoid.WalkSpeed = original_speed
end
end)
Can I see the size of your zone? Also, one thing you can do is to check if the player’s walkspeed is more than the zone speed, which would mean that they are jumping, and make it avoid changing your walkspeed then.
im pretty sure touchended fires and touched fires again constantly for the same part if youre moving through another part im not sure why that happens even though youre still touching it. maybe consider using GetPartsInBoundingBox or something like that
Alright so that gets rid of one of my concerns which is that the player is jumping out of bounds. Try using the condition I told you about in my previous post.
I tried out the condition you provided, and the result is that the zone continues to override the localplayer walkspeed even though it’s supposed to return if hit.Parent.Humanoid.WalkSpeed > new_speed.
script.Parent.TouchEnded:Connect(function(hit)
if hit.Parent:FindFirstChild("WalkspeedRegion") and hit.Parent:FindFirstChild("Humanoid") and hit.Parent.Humanoid:GetState() ~= Enum.HumanoidStateType.Jumping then
hit.Parent.WalkspeedRegion:Destroy()
hit.Parent.Humanoid.WalkSpeed = original_speed
end
end)
It checks if the player is in a jumping state before executing the touch ended code.