For example, A player walks into this part and is slowed down to a WalkSpeed of 4.
If they leave the area of the part, or the clone of the part is deleted with :Destroy()
I have tried a couple ways of doing this but the .Touched and .TouchEnded events are much too unreliable and don’t do what I would want them to do. I tried another more advanced way but wouldn’t revert the effects when a clone of the part is destroyed. Any tips?
use :GetTouchingParts() to see if a humanoidrootpart is touching it. If so, do the next couple actions. Make sure you have GetTouchingParts() in a loop so it’ll remove as they leave.
what if the script was in the players legs?
i imagine something like:
local leg = script.Parent
leg.Touched:Connect(function(hit)
for _,v in leg:GetTouchingParts() do
if v.Name == "insert name of the slowing part here" then ------ you could also use :FindFirstChild() for some sort of value that shows that the part slows people
leg.Parent.Humanoid.WalkSpeed = ----- whatever speed here
end
end
end)
leg.TouchEnded:Connect(function(UnTouchedPart)
if UnTouchedPart.Name == "part's name" then
leg.Parent.Humanoid.WalkSpeed = 16
UnTouchedPart:Destroy()
end
end)
because the leg will get touched a lot this should refresh enough to set the players speed back to normal. as I said above you can swap it’s name for a check with :FindFirstChild() to see if the part has some value that classifies it as a slowing part.
I use this method and it seems to work consistently.
local pad = YourPart
pad.Touched:Connect(function(otherPart)
if add == true then
add = false
if players:FindFirstChild(otherPart.Parent.Name) then
if not table.find(TouchingTable, otherPart) then
table.insert(TouchingTable, otherPart)
print(otherPart)
end
end
add = true
end
end)
pad.TouchEnded:Connect(function(otherPart)
if players:FindFirstChild(otherPart.Parent.Name) then
if table.find(TouchingTable, otherPart) then
table.remove(TouchingTable, table.find(TouchingTable, otherPart))
if #TouchingTable == 0 then
print("No touching parts.")
-- toggle CanTouch so it will trigger any touch actions for players if one is currently touching the part
pad.CanTouch = false; task.wait(1); pad.CanTouch = true
end
end
end
end)
I grabbed a script that was not correct. Sorry, it won’t work for multiple people as it was posted.
Use this one and make it a Local Script:
local players = game:GetService("Players")
local player = players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local ws = game:GetService("Workspace")
local part = ws:WaitForChild("Part")
local TouchingTable = {}
local touchPadActive = false
part.Touched:Connect(function(otherPart)
if otherPart.Parent == player.Character then
if not table.find(TouchingTable, otherPart) then
table.insert(TouchingTable, otherPart)
touchPadActive = true
print(player.Name, "is touching part.")
end
end
end)
part.TouchEnded:Connect(function(otherPart)
if otherPart.Parent == player.Character then
if table.find(TouchingTable, otherPart) then
table.remove(TouchingTable, table.find(TouchingTable, otherPart))
if #TouchingTable == 0 then
touchPadActive = false
print(player.Name, "no longer touching part.")
end
end
end
end)
You can convert it to a Server Script if needed. It’s just not setup that way at the moment.
The table is because Roblox touch events are unreliable.
It keeps track of all touching parts and will only stop when ALL parts stop touching.