Make a Part speed a player up while touching it

I’m trying to make it so that when a player is colliding with a part (even though the part is cancollide false, they are still in the “region” of the part aka the size I have it set at), and I’ve tried a few things by combining scripts from the devforum but I can’t get it to work.

What I want to happen is that when a player is in the space of any of those yellow regions, their walkspeed is set to a higher number (30 is a good example), and when they stop colliding with it their walkspeed is set back to normal.

I know a basic outline of what is needed to be done in the script, but I just can’t figure out how to actually execute it.

It’d go something like this roughly (at least this is how I think it’d be executed) (I’m using comments for parts I don’t generally know how to write, or to show what I’m thinking even if the code is wrong (I think)):

local Players = game:GetService("Players")
local SpeedParts = workspace.SpeedPartsFolder:GetChildren()
local humanoid = Players.Character.humanoid

-- A function that setsWalkSpeed in some way, something along the lines of
local function setWalkSpeed(speed) -- this function will be used later on in the touch part function
     if humanoid then
          humanoid.WalkSpeed = speed
     end
end

-- A function for when a player touches a part, we use the setWalkSpeed function to do it
local function PartTouched(part) -- I don't know how to say part touched so I just put it as that, hopefully y'all get what I'm trying to say
     if part:IsA("Part") then
          setWalkSpeed(30)
          print("Player's WalkSpeed changed!")
     else
          setWalkSpeed(16)
     end
end

Hopefully this outline is good enough (I’m not the greatest scripter, this is one of the first scripts in my game the other 2 were ones I asked my friend to guide me through so this is the first on I’ve tried making by myself)!

1 Like

Should probably add this too, it’ll help a little more as all of those parts are named the same so maybe that could help a little more.

In the past I’ve tried something similar, making the player crouch automatically when they come within a certain part like those yellow parts in your picture, but I have yet to come with a good solution. The only way I did over come it is making the player manually do it themselves, or when the player is near a part or area, I make them crouch automatically. There are other options too, like using a conveyor and adjusting it to your liking.
Conveyor from Roblox:
Conveyor.rbxm (7.7 KB)
If those do not help then I am unsure.

I dont think script itself will work

local Players = game:GetService("Players")
local SpeedParts = workspace.SpeedPartsFolder:GetChildren()
local humanoid = Players.Character.humanoid

I not sure if “humanoid” variable will work as intended

You want to increase a player’s walk speed to 30 when they collide with specific parts in your game and revert it to 16 when they stop colliding; to achieve this, create a script that detects part collisions and adjusts the player’s walk speed accordingly using a function to set the walk speed.

I figured out a different way to do it, but thanks for the help!
For anybody trying to figure out how to do this, here is what I did:

local part = script.Parent

part.Touched:Connect(function(hit) -- runs function when a another part touches the speed part
	if hit.Parent.Humanoid then -- check if the touched part is a part of a player
		hit.Parent.Humanoid.WalkSpeed = 30 -- whatever value you want
	end
end)

part.TouchEnded:Connect(function(hit) -- same thing but if the part stops touching it
	if hit.Parent.Humanoid then
		hit.Parent.Humanoid.WalkSpeed = 16 -- whatever value you want
	end
end)