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!