local afkStatus = game.Players.LocalPlayer:WaitForChild("AFKToggle")
local plrInRoundStatus = game.Players.LocalPlayer:WaitForChild("PlayerInRoundStatus")
This is a Server Script in ServerScriptStorage. Basically what is happening is I have two Bool Values being added from a Local Script to the Local Player, and in the server script I am try to find get those for use in that COde. The thing is, the Server Script obviously runs before the Local Script. I've tried PlayerAdded and CharacterAdded countless times but can't get them to work.
Server Script:
local Players = game:GetService("Players") Players.PlayerAdded:Connect(function(player) --Creating the BoolValues local afkStatus = Instance,new("BoolValue") -- Value is false by default afkStauts.Name = "AFKToggle" local plrInRoundStatus = Instance,new("BoolValue") -- Value is false by default plrInRoundStatus.Name = "PlayerInRoundStatus" --Lets create a folder to keep these safe local boolFolder = Instance.new("Folder",player) boolFolder.Name = "boolFolder" afkStatus.Parent = boolFolder plrInRoundStatus.Parent = boolFolder --If you wish to access their values; print(player.boolFolder:FindFirstChild(afkStauts).Value --false will print due to their values automatically being set to false. end)
Hope this helps.
Don't forget, leave an up-vote if this helps.
(This is an answer to RangerGuy's question in the comments, not to the main question)
Anything that needs to run when the player is added does need to be in the PlayerAdded event handler. If you need to access the player in a different event, you'll need to store data in a table (with the player as the key of that table). You can also call other functions from within that event handler and pass the player, if doing so helps organization. Examples:
local Players = game:GetService("Players") local function doSomething(player) -- can put in code that uses 'player' here end local playerData = {} Players.PlayerAdded:Connect(function(player) local data = { Money = 5, -- for instance } playerData[player] = data end) -- Now when some event happens (perhaps a RemoteEvent), you can access playerData: local function remoteEventHandler(player) local data = playerData[player] -- can do something with data here end -- Just remember when storing data per player to remove the data when they leave or else you'll end up with a memory leak: Players.PlayerRemoving:Connect(function(player) playerData[player] = nil end) -- However, if you don't have any data you want to store (for instance, because you're using BoolValues and IntValues and so on), you don't need to have the playerData table at all, you just need to iterate over the players when you want to do something for each player: for _, player in ipairs(Players:GetPlayers()) do if player.Money.Value >= 5 then -- pretending you have an IntValue named Money and wanted to print out all players who have at least 5 print(player, "has", player.Money.Value, "money") end end -- Note that you would want that 'for' loop inside a function that is run in response to an event or else you'll run the loop when the script starts, which in this case would occur before the server has any players