I am trying to make a script that changes a players walk speed and team when they touch a part!

Hey I am trying to make a script that changes a players walkspeed and team when they touch a part but I get this error
image
We have managed to get the team switching done but we are having issues with the walkspeed, we have tried changing stuff around but have found no solution. Me and my friend are new to scripting so any help would be appreciated!

Here is our code

part = script.Parent
script.Parent.CanCollide = false
script.Parent.Anchored = true
part.Touched:Connect(function(TouchedObject)
	if TouchedObject.Parent:FindFirstChild("Humanoid") then
		print("Switching..")
		game.Players:GetPlayerFromCharacter(TouchedObject.Parent).Team = game.Teams["Stage 1"]
		game.Players:GetPlayerFromCharacter(TouchedObject.Parent).WalkSpeed = 55
	end
end)

Thanks

part = script.Parent
script.Parent.CanCollide = false
script.Parent.Anchored = true
part.Touched:Connect(function(TouchedObject)
	if TouchedObject.Parent:FindFirstChild("Humanoid") then
		print("Switching..")
		game.Players:GetPlayerFromCharacter(TouchedObject.Parent).Team = game.Teams["Stage 1"]
		game.Players:GetPlayerFromCharacter(TouchedObject.Parent:FindFirstChild("Humanoid")).WalkSpeed = 55
	end
end)
1 Like

Hi! WalkSpeed is a property of Humanoids, which are found in characters not in the players themselves! You need to get the character of the player, or you can just use the TouchedObject instance since you’ve already verified its parent has a Humanoid in it.

TouchedObject.Parent.Humanoid.WalkSpeed = 55
1 Like

Thank you very much this worked, wasn’t expecting that fast of a response.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.