In this situation, a character is supposed to walk through a building and, once you are in, your walkspeed changes. I know how to change the players walkspeed, but I’m unsure as to how you can have the character have their walkspeed changed once they’re within a certain area. Any ideas on what I can do? Any assistance at all is appreciated : )
You could add a part on the door, make it nocollide then add a touched event and via do it that way
As @lrisDev said. You can do a touched event. You would insert a script into that part and it would look something like this:
script.Parent.Touched:Connect(function(object)
– if statement checking if object.Parent is a character–
–changing the players walkspeed using the “object” parameter–
end)
You can also add a debounce if you want to reduce lag I guess.
The best script I was able to mash together was this one below, since I’m a very inexperienced scripter, and of course it hadn’t worked. Brace yourself, this may get ugly:
local debounce = true
local Player = game.Players.LocalPlayer
local function object(otherPart)
if otherPart.Parent:FindFirstChildWhichIsA("Humanoid") then
debounce = false
Player.Character.Humanoid.Walkspeed = 5
debounce = true
end
end
brick.Touched:Connect(object())
- You did not reference “brick”
- The debounce is not doing anything since you did not add a wait or a if statement seeing if the debounce is true or false.
- Don’t change the walkspeed via the player, do otherPart.Parent.Humanoid.Walkspeed
One thing you can do is fill the room with a huge invisible part which will be the region that changes your walkspeed.
Then add this in a script inside it:
local original_speed = 16
local new_speed = 20 -- speed for the walkspeed region
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)
Whoops, I had included the brick but I didn’t include it when I copied the script
Thank you, this work exactly as I wanted it to!