I'm making a sword that once it kills a player he will get points. But I think its not tagging the player correctly because other swords will tag the player and give it points my sword won't.
Here is the script that deals with the tags, damage, etc. Its located in the blade of the sword and its a 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
Here is my point giving script, It looks for a player that died and then searches for the tag so it can give the player points. I don't think there is anything wrong with this one but you might need it. It's located in the workspace and it's a regular 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+500
end
end
end)
end)
end)
Thank you!

3 comments
line 7 of the local script : what does "player" refer to? i dont see any "player" variable or anything like that
He might've been refering to variable "plr;" however, this script is from ROBLOX's original sword script, & he added an unnecessary "while" loop to the code.
@loulou1112 Alpha is right, I got that tagging code from ROBLOX's original sword script, I thought I could use it. I was also referring to plr. I'm not sure why I added the While loop but its gone now. It's still not working, is there anything else you guys can see that's wrong?