Hey! I have a script that SHOULD add some values to the player when they join. The problem is, it's very inconsistent. Sometimes it adds them, sometimes it doesn't. Why does this happen and how can I fix this? The values in question are InGame, GainedDebris, and Debris. Code:
local DataStore2 = require(1936396537)
local newReward = 25
game.Players.PlayerAdded:Connect(function(player)
repeat wait() until player
if player then
print(player.Name.." has joined.")
-- Values
local inGame = Instance.new("BoolValue", player)
inGame.Name = "InGame"
inGame.Value = false
local gainedDebris = Instance.new("IntValue", player)
gainedDebris.Name = "GainedDebris"
gainedDebris.Value = 0
local debris = Instance.new("IntValue")
debris.Name = "Debris"
debris.Parent = player
-- Datastore
local debrisData = DataStore2("debris", player)
local function debrisUpdate(Value)
debris.Value = debrisData:Get(Value)
end
debrisData:OnUpdate(debrisUpdate)
-- InGame
player.CharacterAdded:Connect(function(character)
character.Humanoid.Died:Connect(function()
character:FindFirstChild("InGame").Value = false
player:LoadCharacter()
end)
end)
else
print("No Player")
end
end)
Edit: No errors, this is NOT for leaderstats. InGame is used in a different script to detect if a player is in a game. Debris is used to update an on-screen counter. GainedDebris is part of a complex system that I won't detail. Also, it never prints “No Player”

3 comments
Are there any errors, or there other script that changes the point leaderstats?
No errors, this is NOT for leaderstats. InGame is used in a different script to detect if a player is in a game. Debris is used to update an on-screen counter. GainedDebris is part of a complex system that I won't detail.
Also, even if the script doesn't add them, it also doesn't print "No Player." Very confusing indeed.