My script is not working, but everything else is working fine? Please help.
So I made a script that when you kill someone, you get exp. However, this is not working. Please advise.
Script inside the NPC:
local humanoid = script.Parent.Humanoid
function dead()
local tag = humanoid:FindFirstChild("creator")
if tag ~= nil then
if tag.Value ~= nil then
local player = game.Players:WaitForChild(tag.Value)
local exp = player:FindFirstChild("Exp")
if exp ~= nil then
exp.Value += 20
end
end
end
end
humanoid.Died:Connect(dead)
Script inside the tool:
local player = game.Players.LocalPlayer
local damage = script.Parent:WaitForChild("Damage")
function TagHumanoid(humanoid, player)
local Creator_Tag = Instance.new("ObjectValue")
Creator_Tag.Name = "creator"
Creator_Tag.Value = player.Name
game:GetService("Debris"):AddItem(Creator_Tag, 2)
Creator_Tag.Parent = humanoid
end
function UntagHumanoid(humanoid)
for i, v in pairs(humanoid:GetChildren()) do
if v:IsA("ObjectValue") and v.Name == "creator" then
v:Destroy()
end
end
end
local function onTouch(hit)
local humanoid = hit.Parent:FindFirstChild("Humanoid") or nil
if humanoid ~= nil then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
TagHumanoid(humanoid,player)
humanoid:TakeDamage(damage.Value)
humanoid.Died:Connect(function()
wait(5)
UntagHumanoid(humanoid)
end)
end
end
local function activated()
local anim = script.Parent:WaitForChild("Animation")
local char = script.Parent.Parent
local humanoid = char.Humanoid
local animtrack = humanoid:LoadAnimation(anim)
animtrack:Play()
end
script.Parent.Handle.Touched:Connect(onTouch)
script.Parent.Activated:Connect(activated)