So i have a script that i want to get money from killing the npc but it doesent work. Any idea how i can get it to work!
Npc kill script:
local Humanoid = script.Parent.Humanoid
function PwntX_X()
local tag = Humanoid:FindFirstChild("Creator")
if tag ~= nil then
if tag.Value ~= nil then
local Leaderstats = tag.Value:FindFirstChild("leaderstats")
if Leaderstats ~= nil then
Leaderstats.Souls.Value = Leaderstats.Souls.Value + 250
wait(0.1)
script:remove()
end
end
end
end
Humanoid.Died:connect(PwntX_X)
And this is the leaderboards script
local dsService = game:GetService("DataStoreService")
local ds = dsService:GetDataStore("SoulsCoins")
game.Players.PlayerAdded:Connect(function(plr)
local folder = Instance.new("Folder", plr)
folder.Name = "leaderstats"
local currency = Instance.new("IntValue", folder)
currency.Name = "Souls"
currency.Value = ds:GetAsync(plr.UserId) or 0
currency.Changed:Connect(function()
ds:SetAsync(plr.UserId, currency.Value)
end)
end)
game.Players.PlayerRemoving:Connect(function(plr)
ds:SetAsync(plr.UserId, plr.leaderstats.Souls.Value)
end)
