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

Why does this exp and gold giving script in my enemy in workspace not work?

Asked by
Nozazxe 107
3 years ago

There are no errors in the out put and I dont know why it does not work. I found it on youtube, heres the script

local hum = script.Parent.Humanoid
hum.Died:Connect(function()
    local tag = hum:FindFirstChild("creator")
    if tag ~= nil then
        if tag.Value ~= nil then
            local lstats = tag.Value.leaderstats
            lstats.Gold.Value = lstats.Gold.Value +10
            lstats.Experience.Value = lstats.Experience.Value +3
        end
    end
end)

1 answer

Log in to vote
0
Answered by
cancle5 120
3 years ago
Edited 3 years ago

Not sure but I think you have to do this way differently. I would do something like

local hum = script.Parent.Humanoid
hum.Died:Connect(function(player)
    player.leaderstats.Gold.Value = player.leaderstats.Gold.Value + 10
    player.leaderstats.Experience.Value = player.leaderstats.Experience.Value + 3
end)

But make sure the leaderstats actually exists. Something similar to that. If it doesn't work I think you need to add some script to the weapon to find the player who killed the NCP. If it's a player, not an NCP then try putting the script in startercharacterscripts. Otherwise, you need to add some code to the weapon. Edit: Use this kind of leaderstats

local DataStore = game:GetService("DataStoreService")
local ds = DataStore:GetDataStore("CashSaveSystem")

game.Players.PlayerAdded:connect(function(player)
    local leader = Instance.new("Folder",player)
    leader.Name = "leaderstats"
    local Cash = Instance.new("IntValue",leader)
    Cash.Name = "Cash"
    Cash.Value = ds:GetAsync(player.UserId) or 0
    ds:SetAsync(player.UserId, Cash.Value)
    Cash.Changed:connect(function()
        ds:SetAsync(player.UserId, Cash.Value)
    end)
end)
0
okay, i will try this. I used creator because its said to specify who killed someone Nozazxe 107 — 3y
0
Doesnt work, sorry mate. "Attempted to index nil with leaderstats" Even though i have stats loaded. Nozazxe 107 — 3y
0
Make sure all the lines are correct and try making some script in the weapon. Also make sure your leaderstats exists and is named what is there. cancle5 120 — 3y
0
Try using this kind of leaderstats script cancle5 120 — 3y
View all comments (3 more)
0
Try using this kind of leaderstats script cancle5 120 — 3y
0
@cancle5 I have style of script like that already. I need to save four leaderstats which I already am doing, I don’t think yours would change anything. Nozazxe 107 — 3y
0
@cancle5 I have style of script like that already. I need to save four leaderstats which I already am doing, I don’t think yours would change anything. Nozazxe 107 — 3y
Ad

Answer this question