None of these print statements are firing and I have no idea why:
game.Players.PlayerAdded:Connect(function(player) -- Fires whenever a player joins the game
local success, owned = pcall(MarketPlaceService.UserOwnsGamePassAsync, MarketPlaceService, player.UserId, 98681915) -- Checks if player owns the "2X kills gamepass", pcall just means it keeps calling it until its successful
if success and owned then -- Sets an attirbute to true if they own it, I check if this attritbute is true in my killHandler script and if it is I give +2 kills instead of +1
player:SetAttribute("GamepassOwned", true)
elseif not success then
player:Kick("Failed to retrieve gamepass data. Please rejoin!")
else
player:SetAttribute("GamepassOwned", false)
end
player:SetAttribute("Kills", 0)
player:SetAttribute("Deaths", 0)
player:GetAttributeChangedSignal("InGame"):Connect(function() -- If the value changes this function is called
updateResetButton:FireClient(player) -- Fires the client to disable/enable the reset button based on the value
end)
player:SetAttribute("InGame", false) -- The reason I set it to false and then true is because if i just set it to false straight away, the value changed function wouldn't be called, so I set it to true then false so its called when a player first joins the game too
-- THIS IS WHAT ISN'T WORKING
player.CharacterAdded:Connect(function()
print("Char Added")
if player:GetAttribute("InGame") == false then
print("Called :)")
local winstreakGuiClone = winstreakGui:Clone()
winstreakGuiClone.Parent = workspace[player.Name].Head
if player.leaderstats:FindFirstChild("Winstreak").Value == 0 then
print("0 Winstreak)")
winstreakGuiClone.Enabled = false
else
winstreakGuiClone.Enabled = true
end
end
end)
I thought i’d keep the code above the characterAdded event in incase it had something to do with it. Thanks for any help
you might be connecting the event after the players character already loaded, try joining the game and resetting ur character, then it should print, to fix this you can just add
local character = player.Character or player.CharacterAdded:Wait()
in the first line of the playeradded event, then do all your stuff that you do in the characteradded function outside of it too
Thank you both for your help, the function is getting called now, only issue is its saying that “rafferty05” is not in the workspace, even though it is. Any ideas why?
game.Players.PlayerAdded:Connect(function(player) -- Fires whenever a player joins the game
player:GetAttributeChangedSignal("InGame"):Connect(function() -- If the value changes this function is called
updateResetButton:FireClient(player) -- Fires the client to disable/enable the reset button based on the value
end)
player:SetAttribute("InGame", false) -- The reason I set it to false and then true is because if i just set it to false straight away, the value changed function wouldn't be called, so I set it to true then false so its called when a player first joins the game too
player.CharacterAdded:Connect(function()
print("Char Added")
if player:GetAttribute("InGame") == false then
print("Called :)")
local winstreakGuiClone = winstreakGui:Clone()
winstreakGuiClone.Parent = workspace:FindFirstChild(player.Name).Head
if player.leaderstats:FindFirstChild("Winstreak").Value == 0 then
print("0 Winstreak)")
winstreakGuiClone.Enabled = false
else
winstreakGuiClone.Enabled = true
end
end
end)
Output:
’ Char Added - Server - LobbyHandler:27
15:38:30.294 Called - Server - LobbyHandler:29
15:38:30.294 ServerScriptService.LobbyHandler:31: attempt to index nil with ‘Head’
CharacterAdded event provides a character argument, change player.CharacterAdded:Connect(function()
to player.CharacterAdded:Connect(function(char)
and instead of doing workspace:FindFirstChild(player.Name), you can just do char.Head