✓ Accepted answer
One way is to just check if what hit has a humanoid. The other way is to see if the name of what hit is a player, I combined them both here.
script.Parent.Touched:Connect(function(playerlol)
if playerlol.Parent:FindFirstChild("Humanoid") and game.Players[playerlol.Parent.Name] then
print"is a player"
playerlol.Parent.Humanoid.WalkSpeed = 100
playerlol.Parent.Humanoid.JumpPower = 80
game.Workspace.Gravity = 100
game.Workspace.Song:Play()
end
end)
However, like Avigant said, playerlol.Parent could be nil, so to account for this there's an other way to test if it's a character. This is by using GetPlayerFromCharacter() which returns the player associated with the given character.
To use it, write the following code.
script.Parent.Touched:Connect(function(playerlol)
if playerlol.Parent and game:GetService("Players"):GetPlayerFromCharacter(playerlol.Parent) then
print"is a player"
playerlol.Parent.Humanoid.WalkSpeed = 100
playerlol.Parent.Humanoid.JumpPower = 80
game.Workspace.Gravity = 100
game.Workspace.Song:Play()
end
end)
1 comment
connect is deprecated. Use Connect instead.