Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 5 years ago
Edited 5 years ago

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

Log in to vote
0
Answered by
aazkao 787 Moderation Voter
5 years ago

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)
Ad

Answer this question