So I wanted to make a sword that give points when I kill an NPC or a Player like the sword model ROBLOX provided here’s my script. Idk how to make it work though
> local Debris = game:GetService("Debris")
> local damage = 10
> local debounce = true
>
> function TagHumanoid(humanoid, player)
> local Creator_Tag = Instance.new("ObjectValue")
> Creator_Tag.Name = "creator"
> Creator_Tag.Value = player
> Debris:AddItem(Creator_Tag, 2)
> if humanoid then
> Creator_Tag.Parent = humanoid
> end
> 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
>
> function attack(player)
> print("attack function called")
> local hitbox = script.Parent
> hitbox.Touched:Connect(function(hit)
> local humanoid = hit.Parent:FindFirstChild("Humanoid")
> if humanoid and debounce then
> humanoid:TakeDamage(damage)
> print("damaged humanoid by " .. damage)
> UntagHumanoid(humanoid)
> TagHumanoid(humanoid, player)
>
> debounce = false
> wait(1)
> debounce = true
> end
> end)
> end
>
>
>
> script.Parent.Parent.Activated:Connect(function()
> local success, err = pcall(function()
> end)
> if success then
> attack()
> end
> ```
> end)