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

I am trying to check if a player has loaded In but nothing works. what is your ideas?

I am making a round-based game and have been stuck for days. t all works find up until line 31 when it tries to find the bool value loaded inside the players backpack. It gives no error but skips over the if statement and it can't find the boolvalue even though I checked the players backpack during runtime with the value being in the backpack. I have tried everything such as wait for child andmany other slutions people gave out but NOTHING WORKS!

local status = game:GetService("ReplicatedStorage").Status

local games = game:GetService("ServerStorage").Games:GetChildren()

local lobbyMusic = workspace.Music.LobbyMusic

local gameMusic30 = workspace.Music.GameMusic30

local gameMusic60 = workspace.Music.GameMusic60

local countEffect = workspace.Music.CountEffect

while true do

wait(1)

i = 10

while i ~= -1 do

wait(1)

status.Value = "Intermission: "..i

i = i - 1

end

status.Value = "Selecting Game"

wait(5)

local rand = math.random(1,#games)

local chosenGame = games[rand]

local clone = chosenGame:Clone()

clone.Parent = workspace

status.Value = "Game Chosen: "..games[rand].Name

wait(3)

status.Value = "Teleporting"

wait(2)

status.Value = "Game In Progress"

local points = clone.SpawnPoints:GetChildren()

for i,v in pairs(game:GetService("Players"):GetChildren()) do

local char = v.Character

local rand = math.random(1,#points)

if v.Backpack:FindFirstChild("Loaded")then

char.HumanoidRootPart.CFrame = points[rand].CFrame

moduleMain = require(chosenGame.MainScript)

v.Backpack.InGame.Value = true

end

end

for i = 5,0,-1 do

wait(1)

status.Value = "Game In Starting: "..i

end

wait()

for i = chosenGame.GameTime.Value, 1,-1 do

wait(1)

status.Value = "Game In Progress: "..i - 1

end

wait(.5)

status.Value = "Game Over"

wait(2)

local winners = {}

for i,v in pairs(game:GetService("Players"):GetChildren())do

if v.Backpack.Won.Value == true then

winners[i] = v.Name

end

end

wait()

for i = 0, 5 do

wait()

lobbyMusic.Volume = lobbyMusic.Volume + .1

i = i + 1

end

wait()

status.Value = "Winners Are: "..table.concat(winners,", ")

for i,v in pairs(game:GetService("Players"):GetChildren()) do

local char = v.Character

if v:WaitForChild("InGame").Value == true then

char.Humanoid.Health = 0

end

end

end

1 answer

You can use the PlayerAdded event, which runs everytime a player joins the game, or if you mean the player's character, use the CharacterAdded event, which will run everytime the player's character spawns in, including when it respawns after being killed.

local Players =  game:GetService("Players")

local  function onCharacterAdded(character)
	print(character.Name ..  " has spawned")
end

local  function onCharacterRemoving(character)
	print(character.Name ..  " is despawning")
end

local  function onPlayerAdded(player)
	player.CharacterAdded:Connect(onCharacterAdded)
	player.CharacterRemoving:Connect(onCharacterRemoving)
end

Players.PlayerAdded:Connect(onPlayerAdded)

https://developer.roblox.com/api-reference/event/Player/CharacterAdded

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