Hey. I'm trying to find a player that touched a part. Now, to find it, I set a variable that will make the parent of the parent of the thing that touched a string. Then I will find it in players and change it's team if it's equal to a specific team. It's not working for me. I think I used tostring wrong. Can someone help me? Here's my script :

function onTouch(hit)
	if hit.Parent ~= nil then
		local PlayerName = tostring(hit.Parent.Parent.Name)
		if game.Players.PlayerName.Team == game.Teams.Prisoners then
			game.Players.PlayerName.Team = game.Teams.Criminals 
		else
			print("A person from other team has touched that.")
		end
	end
end

script.Parent.Touched:Connect(onTouch)

3 comments

0

You have to get the character and then the player. local character = hit.Parent, local player = game:GetService("Players"):GetPlayerFromCharacter(character)

0

Thank you it worked!

0

Np