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

How To Get Exp When A Humanoid Dies?

I've had 2 of this same questions in different forums and no one can figure why it doesn't work. I have a basic roblox dummy in the workspace and it has a humanoid and everything. So When I Kill the Dummy the GiveExp Script says {xp is not a valid member of Folder}, here is the scripts.

----Leaderstats Script(Normal Script)----

game.Players.PlayerAdded:Connect(function(plr)
    local leaderstats = Instance.new("Folder")
    leaderstats.Parent = plr
    leaderstats.Name = "Leaderstats"
	 
	    local lvl = Instance.new("IntValue")
	    lvl.Parent = leaderstats
	    lvl.Name = "Level"
	 
	    local xp = Instance.new("IntValue")
	    xp.Parent = leaderstats
        xp.Name = "Exp"

   end)

----GiveExp Script (Normal Script)----

local leaderstats = game.Players.LocalPlayer:WaitForChild("Leaderstats")

game.Workspace.Dummy.Humanoid.Died:Connect(function()
	        leaderstats.Exp.Value = leaderstats.xp.Value + 10000
	   end)
	

I've have asked this so many times and no brilliant mind can figure this out, could somebody take the time to help this old lad?

1 answer

There's no such thing as LocalPlayer in Server Scripts. You're also doing xp.Value instead of Exp.Value

3 comments

0

Could you show the code that I should change/fix?

0

For your script to work, you'd have to create another script which detects which player killed it and such, which I don't have time for right now, sorry.

0

*and after you have the payer, copy your give xp script but fix the things I pointed out.

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