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

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

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

1 comment

0

LocalPlayer is nil to the server.

1 answer

✓ Accepted answer

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.

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