I'm making a sword that once you kill someone with it you receive points. For some reason it only works with linked swords and not my custom sword. Please help, thank you!
Sword code, Located in the blade of the sword: Local script
wait(0.01)
local CanDamage = true
local plr = game.Players.LocalPlayer
local function tagHumanoid(humanoid, player)
local creator_tag = Instance.new("ObjectValue")
creator_tag.Value = player
creator_tag.Name = "creator"
creator_tag.Parent = humanoid
end
local function untagHumanoid(humanoid)
if humanoid ~= nil then
local tag = humanoid:FindFirstChild("creator")
if tag ~= nil then
tag.Parent = nil
end
end
end
while true do
wait(0.01)
script.Parent.Touched:connect(function(hum)
if hum and hum.Parent:FindFirstChild("Humanoid") then
if CanDamage == true then
tagHumanoid(hum, plr)
CanDamage = false
hum.Parent.Humanoid:TakeDamage(10)
plr.swordlvl.Value = plr.swordlvl.Value + 2
wait(0.8)
untagHumanoid(hum)
CanDamage = true
end
end
end)
end
Point giver script, Located in workspace: Script:
game.Players.PlayerAdded:connect(function(p)
p.CharacterAdded:connect(function(c)
c.Humanoid.Died:connect(function()
local cv = c.Humanoid:findFirstChild("creator")
if cv then local k = cv.Value
if k and k ~= p then
k.leaderstats.Bounty.Value = k.leaderstats.Bounty.Value+150
end
end
end)
end)
end)
Leaderboard script, Located in ServerScriptService (just in case this is needed): Script:
function playerAdded(plr)
local stats = Instance.new("IntValue", plr)
stats.Name = "leaderstats"
local bounty = Instance.new("IntValue", stats)
bounty.Name = "Bounty"
bounty.Value = 0
local level = Instance.new("IntValue", stats)
level.Name = "Level"
level.Value = 1
local exp = Instance.new("IntValue", plr)
exp.Name = "exp"
exp.Value = 0
local money = Instance.new("IntValue", stats)
money.Name = "Gold"
money.Value = 0
local max = Instance.new("IntValue", plr)
max.Name = "maxexp"
max.Value = 5
local swordlvl = Instance.new("IntValue", plr)
swordlvl.Name = "swordlvl"
swordlvl.Value = 0
local swordlvlmain = Instance.new("IntValue", plr)
swordlvlmain.Name = "swordlvlmain"
swordlvlmain.Value = 0
local swordlvlmax = Instance.new("IntValue", plr)
swordlvlmax.Name = "swordlvlmax"
swordlvlmax.Value = 5
end
game.Players.PlayerAdded:connect(playerAdded)
Soooo sorry for the long post :(
