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

Value is not changing after the humanoid dies, anyone know why?

Regular script in workspace.

local human = script.Parent.Humanoid
human.Died:Connect(function(player)
		player.leaderstats.Experience.Value = player.leaderstats.Experience.Value + 5
end)

Basically, if the player kills the enemy, the value "experience" should increase by 5, but it doesn't, instead it gives me this " 16:53:46.035 - Workspace.Model.Zombie.EXPGiver:3: attempt to index local 'player' (a nil value)". Anyone could tell me what causes this error message and how to make this script work?

2 comments

0

you wrote player. You didnt define "player"

0

no

2 answers

The error is saying that the player is never defined.

The died function doesn't return any result, thus you are getting a nil result.

You need some script that adds the player's name to the enemy, something like (I'll do in pseudo code):

If player hurts enemy, overwrite "whoHitEnemy" (a string variable, maybe in the enemy's humanoid) to player name

so then (in code):

local human = script.Parent.Humanoid
human.Died:Connect(function()
	local whoHitName = Humanoid.whoHitEnemey.Value
	local player
	if game.Players:FindFirstChild(whoHitName) then
		player = game.Players:FindFirstChild(whoHitName)
	end
	if player==nil then
	else
       	player.leaderstats.Experience.Value = player.leaderstats.Experience.Value + 5
	end
end)

Roblox tools insert an object value into the humanoid named "creator" this script should help

script.Parent.Humanoid.creator.Value.leaderstats.Experience.Value = script.Parent.Humanoid.creator.Value.leaderstats.Experience.Value + 5

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