I'm writing a script to make coins fall out of a player on death. It's a localscript and it is in StarterGUI. I get the error 'attempt to index local 'Character' (a nil value)'
How could I fix this?
This is the code :
local Player = script.Parent.Parent
local Character = game.Workspace:FindFirstChild(Player.Name)
local CharTorso = Character.Humanoid
function onDied()
for i =1,script.GoldCount.Value do
local xp = Instance.new("Part")
xp.Parent = game.Workspace
xp.Position = Character.Torso.Position + Vector3.new(math.random(-3,3),math.random(-3,3),math.random(-3,3))
xp.Shape = 0
xp.formFactor = "Symmetric"
xp.Name = "XP"
xp.BrickColor = BrickColor.new(24)
xp.Reflectance = 0.5
xp.Size = Vector3.new(1,1,1)
local clone = script.Increase:Clone()
clone.Disabled = false
clone.Parent = xp
end
end
CharTorso.Died:connect(onDied)
Any help is appreciated!

6 comments
Hi UserOnly16Characters, Thanks for helping out! It works and everything!
No problem,I would appreciate it if you could accept my answer! :)
Sorry, But how do I accept an answer? I am really new to this website. xD
Beneath the "ANSWERED BY" thing there is this thing called "Accept Answer" which will give you and me one reputations.
Ctrl + F , search Accept Answer
It's not there O_O