Npcs/players give money on kill?

Wait, did this print? It should’ve, cause you said the Value print worked?

1 Like

It printed my username cause thats what i changed the value to

Alright so the only other assumption, is that there’s not a leaderstats object that’s Parented inside your Player

Can you check your Explorer hierarchy when you start the game, and head to game.Players.11neptune to see if you have something named “leaderstats” inside?

1 Like

Yep there is a folder called leaderstats and before you ask there is a value called credits.

Hm, alright

local Humanoid = script.Parent.Humanoid

local function GiveMoney()
    local Tag = Humanoid:FindFirstChild("creator")
    print("Event fired")

    if Tag and Tag.Value then
        print("Found a valid player")
        local Player = Tag.Value
        
        local leaderstats = Player:FindFirstChild("leaderstats")
        print(leaderstats)

        if leaderstats then
            print("Found the leaderstats")
            leaderstats.Credits.Value += 50
        end
    end
end

Humanoid.Died:Connect(GiveMoney)

Can you try this script?

1 Like

17:09:14.974 Event fired - Server - money kill:5
17:09:14.975 Found a valid player - Server - money kill:8
17:09:14.976 Workspace.Normal Dummy .money kill:11: attempt to call a nil value - Server

Heres what got outputted
I swear this is never gonna end 0-0

The only assumption I’m assuming is that leaderstats is not valid to what you’re trying to find

Try doing

local leaderstats = Player:WaitForChild("leaderstats")

Exact same error as last time why is this so hard ;-;

Ok the only other thing is to show the Explorer hierarchy cause this is getting ridiculous (Preferably where the Script is, and where the leaderstats are when you join the game)

The thing is though, it shouldn’t be defined as nil if there’s already a leaderstat object in the Player object? We’ve done tons of sanity checks


The script called PlayerHandeler has the leadboard script

The script called money kill the money giving script

Do show where the leaderstats are when you press play as well, cause that’s the thing that’s confusing me the most


On the right side

local Character = script.Parent
local Humanoid = Character.Humanoid

Humanoid.Died:Connect(function()
    local Tag = Humanoid:FindFirstChild('creator')

    if Tag and Tag.Value then
        local Player = Tag.Value
        print(Player, Player:IsA('Player'))
        
        local leaderstats = Player:FindFirstChild('leaderstats')
        if leaderstats then
           leaderstats.Credits.Value += 50
        end
    end
end)
1 Like

The issue has been resolved through PM’s hopefully

There was a StringValue creator object parented inside the Humanoid’s Object before even starting the game, which kept resulting as nil values since they weren’t overridden

image

4 Likes