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

Why doesn't this value be set to true when the player joins the game for the first time?

Asked by
Vxpper 101
5 years ago

Script in ServerScriptService:

wait(5)
game.Players.PlayerAdded:Connect(function()
    if game.Players.LocalPlayer.hasJoined.Value == false then
        game.Players.LocalPlayer.hasJoined.Value = true
    end
end)

Script in LocalScript in StarterGui:

local joinedVal = game:GetService("Players").LocalPlayer.hasJoined

if joinedVal.Value == false then
    script.Parent.MainUI.StarterPack.Visible = true
elseif
    joinedVal.Value == true then
    script.Parent.MainUI.StarterPack.Visible = false
end
0
LocalPlayer is nil to the server. User#19524 175 — 5y

1 answer

Log in to vote
0
Answered by
green271 635 Moderation Voter
5 years ago

Question: Value does not set when player joins the game.

With FilteringEnabled, the server cannot access LocalPlayer. Since FE is now enabled for all games, this is mandatory to know. This means that doing game.Players.LocalPlayer in a Server Script will NOT work!

What can you do? Relevant to this answer, you can use the first paramater of PlayerAdded.

Here's the updated code below:

wait(5) 
game.Players.PlayerAdded:Connect(function(plr) -- grabbing the plr that joined
    if plr.hasJoined.Value == false then -- replace LocalPlayer with our newly grabbed player
        plr.hasJoined.Value = true -- replace LocalPlayer with our newly grabbed player
    end
end)

If you're not using PlayerAdded, you can use RemoteEvents and the likes in order to grab the player.

Ad

Answer this question