So I am making a fighting games but where you fight NPC’s and I have been doing experiments and I a NPC kill for cash leaderboard and when you kill an NPC you get rewarded with 15 cash. My problem/experiment is that when I kill a NPC with the default roblox sword it gives me cash. But when I do it with the guns I made and certain guns from the toolbox it does nothing. How could I make it to where when I kill an NPC with ANY weapon it counts for cash. Here is the leaderstats script:
game.Players.PlayerAdded:Connect(function(plr)
local leaderstats = Instance.new("Folder", plr)
leaderstats.Name = "leaderstats"
local Cash = Instance.new("IntValue", leaderstats)
Cash.Name = "Cash"
end)
Yes a very basic leaderboard.
Here is the NPC's Cash script:
script.Parent.Zombie.Died:connect(function() --The NPC's Humanoid is named Zombie
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.Cash.Value = leaderstats.Cash.Value + 15
wait(0)
end
end
end
Thanks
I have also learned that melee weapons like swords and stuff have a better outcome percentage. But guns have a low percentage chance of working. I would like to have more guns than melee weapons.
For example, let’s say you wanted to tag the zombie after the player has shot it.
function OnHit(hit)
if hit.Parent then
local hum = hit.Parent:FindFirstChild("Humanoid")
if hum then
--Do Damage
-- Add a tag to the zombie
local tag = Instance.new("ObjectValue",hit.Parent)
tag.Name = "creator"
tag.Value = plr -- Player who fired the gun
end
end
end
If you want to add a tag only when the player has KILLED the zombie, you can do this instead:
function OnHit(hit)
if hit.Parent then
local hum = hit.Parent:FindFirstChild("Humanoid")
if hum then
--Do Damage
-- Add a tag to the zombie
if hum.Health <= 0 then --Player has killed the zombie because Health is lower than 0
local tag = Instance.new("ObjectValue",hit.Parent)
tag.Name = "creator"
tag.Value = plr -- Player who fired the gun
end
end
end
end
Wait, also you are calling .Died on the Zombie itself? .Died is an event fired by the humanoid, so you have to do script.Parent.Zombie.Humanoid.Died instead.