Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why is this sword not being destroyed?

Hi!

This code is supposed to delete a player's sword when the player gets a kill, but it only works in studio and not in a server/local server. It is in a local script that is in the sword and I have tested the script that counts the player's kills and the IntValue does go up when I get a kill, but never deletes the sword.

game.Players.LocalPlayer.HiddenStats.Kills.Changed:Connect(function()
	script.Parent:Destroy() -- this is a test and has no use
end)

Thank you for reading!

1 answer

✓ Accepted answer

###This is because you're doing it on the client, you'll want to do it in the server. Place a RemoteEvent in the ReplicatedStorage or inside the sword.

script.Parent.RemoveTool.OnServerEvent:Connect(function(player)
    if player.Character:FindFirstChild(script.Parent.Name) then
        player.Character[script.Parent.Name]:Destroy()
    end
    
    if player.Backpack:FindFirstChild(script.Parent.Name) then
        player.Backpack[script.Parent.Name]:Destroy()
    end	
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.