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

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

Asked by 5 years ago
Edited 5 years ago

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?

0
you wrote player. You didnt define "player" voidofdeathfire 148 — 5y
0
no Gey4Jesus69 2705 — 5y

2 answers

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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)
Ad
Log in to vote
0
Answered by
Imperialy 149
5 years ago
Edited 5 years ago

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

Answer this question