Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Player.CharacterAdded event not running?

Asked by
Jac_00b 157
2 years ago
Edited 2 years ago

Hello, I'm trying to make a localscript about saving cards. When you die, it saves the cards into a table which is then accessed when you respawn and it gives your cards back. However, I can't get the player.CharacterAdded event to work at all. It's not firing when you join or when you die. The first part of the script works fine, it's just the CharacterAdded part that is not working. I'm getting quite frustrated, so I hope someone could please help.

local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local died = false

char:WaitForChild("Humanoid").Died:Connect(function()
    died = true
    cardtable = {}
    for i,v in pairs(script.Parent.Inventory:GetChildren()) do
        if v.Name ~= "UIGridLayout" then
            table.insert(cardtable,v.Name)
        end 
    end
end)

player.CharacterAdded:Connect(function(char)
    print("Added") --never prints
    if died == true then
        for i,v in pairs(cardtable) do
            local newcard = game.ReplicatedStorage.Cards:FindFirstChild(v):Clone()
            newcard.Parent = script.Parent.Inventory
        end
        died = false
    end
end)
0
Where is the script located? NotThatFamouss 605 — 2y

Answer this question