Why does this script result in an error when the SpawnLocation is touched by a player? Output displayed "Humanoid is not a valid member of Workspace."
local debounce = false
script.Parent.Touched:connect(function(hit)
if not debounce then
debounce = true
if hit.Parent.Humanoid.WalkSpeed >= 32 then
hit.Parent.Humanoid.WalkSpeed = hit.Parent.Humanoid.WalkSpeed - 16
end
wait(1)
debounce = false
end
end)
I did find the solution to fix this problem, but is there a better way?
local debounce = false
script.Parent.Touched:connect(function(hit)
if not debounce then
debounce = true
local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
if player then
if player.RespawnLocation ~= script.Parent then
player.RespawnLocation = script.Parent
end
end
if hit.Parent.Name ~= "Workspace" then -- My solution
if hit.Parent.Humanoid.WalkSpeed >= 32 then
hit.Parent.Humanoid.WalkSpeed = hit.Parent.Humanoid.WalkSpeed - 16
end
end
wait(1)
debounce = false
end
end)
Thanks!
