local part = script.Parent part.Touched:connect(function(hit) local hum = hit.Parent:FindFirstChild("Humanoid") if hum then hum.WalkSpeed = 0 local player = game.Players:GetPlayerFromCharacter(hum) player.PlayerGui.PlantBombA.Frame.Visible = true if player.PlayerGui.PlantBombA.Frame.Visible.Changed then hum.WalkSpeed = 16 end end end)
The error is...
16:45:04.936 - Workspace.PlantDetector.Script:7: attempt to index local 'player' (a nil value)
Thanks in advance for any help you may provide!
When using GetPlayerFromCharacter()
, you will want to refer to the character itself and not the humanoid, as the character has the player's name and not the humanoid.
That's pretty much the issue.
Your fixed script:
local part = script.Parent part.Touched:connect(function(hit) local hum = hit.Parent:FindFirstChild("Humanoid") if hum then hum.WalkSpeed = 0 local player = game.Players:GetPlayerFromCharacter(hit.Parent) --If hit.Parent.Humanoid then hit.Parent is a character player.PlayerGui.PlantBombA.Frame.Visible = true if player.PlayerGui.PlantBombA.Frame.Visible.Changed then hum.WalkSpeed = 16 end end end)