You can write your topic however you want, but you need to answer these questions:
**What do you want to achieve? I want to clone the tool once and not duplicate it and then remove it when the player is no longer sitting
What is the issue? Include screenshots / videos if possible! The tools are not destroying instead of cloning once and destroying when the player is no longer sitting
What solutions have you tried so far? Did you look for solutions on the Developer Hub? Yes
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
local Destory_Tool = game.ReplicatedStorage.SledgeHammer
local Player = game.Players.LocalPlayer
local Player_Char = Player.Character or Player.Character:Wait()
local Player_Hum = Player_Char:WaitForChild("Humanoid")
local Seat = game.Workspace.SeatModel.SeatPart.Seat
Player_Hum.Seated:Connect(function(Sit, Part)
if Sit then
local Tool_Giver = Destory_Tool:Clone()
Tool_Giver.Parent = Player.Backpack
else
print("Destorying the tool")
-- the player gets up from the seat
Destory_Tool:Destroy()
print("Destoryed")
end
end)
So, I got a problem where my tools are cloning Mutiple times when a player sits instead of destroying why is this happening?
You should be giving players tools on the server, not on the client.
The other problem is that you’re deleting Destroy_Tool, which is just the copy of the tool in ReplicatedStorage. Once you destroy it, it probably still exists in nil because you still reference it in your code with Destroy_Tool.
tl;dr; you delete the template, not the new tool in the player’s inventory.
This code is a working version of your code, though it’s still client sided and it should very likely be server sided:
local templateTool = game.ReplicatedStorage.SledgeHammer
local player = game.Players.LocalPlayer
local playerChar = Player.Character or Player.Character:Wait()
local playerHum = Player_Char:WaitForChild("Humanoid")
local seat = game.Workspace.SeatModel.SeatPart.Seat
local givenTool
playerHum.Seated:Connect(function(sit, part)
if sit then
givenTool = templateTool:Clone()
givenTool.Parent = player.Backpack
else
print("Destorying the tool")
-- the player gets up from the seat
givenTool:Destroy()
print("Destoryed")
end
end)
To make the code server sided start a new piece of code in a script and use Players.PlayerAdded to get players and Player.CharacterAdded to get character and humanoids, then use the same events and stuff.
The Destory_Tool is the item in replicated storage, not the clone.
The clone of the item is called Tool_Giver and it is made inside the if-statement.
However, if this is all local, and you only ever need one of them, why destroy it at all? Maybe you could just make one at the start, and set the parent to nil instead of destroying it.
Otherwise, you will at least have to store the reference to the tool you cloned in a variable created outside the seated event.
local Destroy_Tool = game.ReplicatedStorage.SledgeHammer
local Player = game.Players.LocalPlayer
local Player_Char = Player.Character or Player.Character:Wait()
local Player_Hum = Player_Char:WaitForChild("Humanoid")
local Seat = game.Workspace.SeatModel.SeatPart.Seat
local Tool_Giver
Player_Hum.Seated:Connect(function(Sit, Part)
if Sit then
Tool_Giver = Destroy_Tool:Clone()
Tool_Giver.Parent = Player.Backpack
else
print("Destroying the tool")
-- the player gets up from the seat
Tool_Giver:Destroy()
print("Destroyed")
end
end)