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

script wont update textlabel in localplayer.playergui but it does in startergui why?

Asked by 2 years ago

Hello, I am trying to make game where you find endings and it counts up how many you have on an gui. I put in script on part touched it goes to playergui and updates text there from 0/13 found to 1/13 found. It worked in startergui it updated the text but when i put it to playergui it doesnt do nothing.

script.Parent.Touched:Connect(function(part)
    if part.Parent:FindFirstChild("HumanoidRootPart") then
        script.Parent.Parent.Parent.Parent.Players.LocalPlayer.PlayerGui.EndingGui.Menu.Easyendings.oo13.Text = "1/13 found"
    end
end)

1 answer

Log in to vote
0
Answered by 2 years ago
Edited 2 years ago

LocalPlayer can NOT be accessed via server-side.

It is the LocalPlayer of the client but since a script is not a client script, it obviously doesn't work

You can use GetPlayerFromCharacter()

script.Parent.Touched:Connect(function(part)
    if part.Parent:FindFirstChild("HumanoidRootPart") then     
    local player = game.Players:GetPlayerFromCharacter(part.Parent) -- It gets a model and gets the player of the character
    if player then 
        player.PlayerGui.Ending.Text = '1/13 found' -- I think you mean text
    end

    end
end)

It is really unnecessary to go like script.Parent until it reaches game and do .Players.

You can easily use game.Players

Ad

Answer this question