local Human = script.Parent:WaitForChild"Humanoid" local Player = game.Players:GetPlayerFromCharacter(script.Parent) Human.Died:Connect(function() if Player then local Krak = Player:FindFirstChild"leaderstats":FindFirstChild"Krak" if Krak then Krak.Value = Krak.Value - 20 end end local Creator = Human:FindFirstChild"creator" if Creator and Creator.Value and Creator.Value:FindFirstChild"leaderstats" and Creator.Value.leaderstats:FindFirstChild"Krak" then Creator.Value.leaderstats["Krak"].Value = Creator.Value.leaderstats["Krak"].Value + 25 end end)
I have this script here, it's supposed to go inside of Zombie and give the player 25 dollars ("Krak" the name of the currency I'm using for my game) every time the humanoid reaches 0 health. It works for the first two times that the script runs but then it just appears to run but not yield any Krak. There is no output into the console whatsoever. I have tried for days doing research with one of my friends to find any possible issues, we found nothing. I'm hoping its just a simple fix I could get some help with here. Below is also my leaderboard script if that helps any. Thanks in advance!
local Players = game:GetService("Players") local function leaderboardSetup(player) local leaderstats = Instance.new("Folder") leaderstats.Name = "leaderstats" leaderstats.Parent = player local Krak = Instance.new("IntValue") Krak.Name = "Krak" Krak.Value = 10000 Krak.Parent = leaderstats end Players.PlayerAdded:Connect(leaderboardSetup)
I would recommend doing it like this, this script goes inside the thing to kill:
local tagHelp = script.Parent script.Parent:FindFirstChild("Humanoid").Died:Connect(function() if tag ~= nil then if tag.Value ~= nil then local leaderstats = tag.Value:FindFirstChild("leaderstats") local krak = leaderstats:FindFirstChild("Krak") if krak then krak.Value += 20 end end end end)
In your weapon script that deals the damage do this:
local function tagCreator(NPC, player) local Creator_Tag = Instance.new("ObjectValue") Creator_Tag.Name = "creator" Creator_Tag.Value = player Creator_Tag.Parent = NPC game:GetService("Debris"):AddItem(Creator_Tag, 2) Creator_Tag.Parent = game.Workspace:FindFirstChild(NPC.Name) end --Un tags the victim if someone has already tagged them local function unTag(NPC) for i, v in pairs(NPC:GetChildren()) do if v:IsA("ObjectValue") and v.Name == "creator" then v:Destroy() end end end
In the weapon script where the weapon checks if the object is a player and damages them add this:
local NPCthing = Humanoid.Parent unTag(NPCthing) tagCreator(NPCthing, player)
If you need any help with what I mean feel free to ask :) Also if there are any errors just say.