Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

It won't change the value to the name of the play?

I don't know why this script won't work?

script.Parent.Touched:connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		local PlayerName = hit.Parent.Name
		--Player One--
		local Gui = script.Parent.Parent.PlayersInMatchPart.PlayersInMatchGui
		if Gui.Player1.Taken.Value == 1 and Gui.Player1.Name.Value ~= PlayerName then
			Gui.Player1.Taken.Value = 2
			print(PlayerName.userId)
			Gui.Player1.Name.Value = PlayerName
		end
	end
end)
end)

Error: Workspace.MatchMakingArea.MatchFinderPart.OnTouch:8: attempt to index field 'Name' (a string value)

Also when I print our the players Id it just says nil?

1 answer

✓ Accepted answer

Because playerName is a string value, you assigned a string to it e.g "zombaScripts" at line3, if you want to get the userId then just assign the player object instead

script.Parent.Touched:connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
        local Player = hit.Parent
        --Player One--
        local Gui = script.Parent.Parent.PlayersInMatchPart.PlayersInMatchGui
        if Gui.Player1.Taken.Value == 1 and Gui.Player1.Name.Value ~= Player.Name then
            Gui.Player1.Taken.Value = 2
            print(Player.userId)
            Gui.Player1.Name.Value = Player.Name
        end
    end
end)
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.