Problems You’ve Encountered
Okay, first of all, I’m assuming the StarterCharacterScripts script is a local script, which is the first problem. Although the part may be deleting, it is only on the local side. I advise you to move the script somewhere on the server, or fire a remote event and receive it on the script you just sent to delete the Motor6D and Weight Model there (I will cover how to do this later.)
Second, I recommend using Humanoid.Jumping instead of User Input Service for this.
Now here is where the problems come in. Using WaitForChild will yield the script until it can find the item it is looking for. If it can’t find the item, eventually it will time out since you have not specified the TimeOut parameter. For what you are trying to fulfill, I believe this is a bad way to achieve it.
Why it was only firing once
The reason your script was only firing once was because you sat in the seat the first time soon enough before the TimeOut happened. Variables are only established once in the beginning of the script. After deleting the items, WaitForChild doesn’t continue to search for them, so it just stops working.
More Information on WaitForChild Here
Instance | Documentation - Roblox Creator Hub
Approaching the Problem
Now to actually solve the problem, using what I told you, you can create something like this
local UserInputService = game:GetService("UserInputService")
local seats = {
game.Workspace:WaitForChild("BenchSeat1")
}
local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")
local humanoidRootPart = character:WaitForChild("HumanoidRootPart")
local rightHand = character:WaitForChild("RightHand")
local sitting = false
local debounce = false
humanoid.Jumping:Connect(function(isJumping)
-- looking for the items
local motor6D = rightHand:FindFirstChild("BenchpressMotor6D")
local weightModel = rightHand:FindFirstChild("BasicBenchPressWeights")
-- even if the items aren't found, the whole script shouldn't stop working in the future
if motor6D and weightModel then -- actually checks if character has items
-- destroying items if player doesn't have them
weightModel:Destroy()
motor6D:Destroy()
end
end)
humanoid:GetPropertyChangedSignal("SeatPart"):Connect(function()
if table.find(seats, humanoid.SeatPart) then
sitting = true
else
sitting = false
end
end)
Notice how this time I check if the player has the motor6D and weight model every time they jump instead of assuming they will have it with WaitForChild. As I mentioned earlier, this is local sided, so the items will only be destroyed on the client, which is very bad, so I will show you how to use a remote event to destroy the items on the server side.
Using Remote Event (Highly Recommended)
Local Script
local UserInputService = game:GetService("UserInputService")
local seats = {
game.Workspace:WaitForChild("BenchSeat1")
}
local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")
local humanoidRootPart = character:WaitForChild("HumanoidRootPart")
local rightHand = character:WaitForChild("RightHand")
local sitting = false
local debounce = false
humanoid.Jumping:Connect(function(isJumping)
local motor6D = rightHand:FindFirstChild("BenchpressMotor6D")
local weightModel = rightHand:FindFirstChild("BasicBenchPressWeights")
if motor6D and weightModel then
SomeEvent:FireServer() -- fires event to server instead destroying them here
end
end)
humanoid:GetPropertyChangedSignal("SeatPart"):Connect(function()
if table.find(seats, humanoid.SeatPart) then
sitting = true
else
sitting = false
end
end)
Server Script
SomeEvent.OnServerEvent:Connect(function(player) -- firing to server automatically gives player parameter
local character = player.Character
local rightHand = character:FindFirstChild("RightHand")
local motor6D = rightHand:FindFirstChild("BenchpressMotor6D")
local weightModel = rightHand:FindFirstChild("BasicBenchPressWeights")
motor6D:Destroy()
weightModel:Destroy()
end)
You can also do this by passing the objects as arguments on the remote event like this:
Targeted Section of Local Script
humanoid.Jumping:Connect(function(isJumping)
local motor6D = rightHand:FindFirstChild("BenchpressMotor6D")
local weightModel = rightHand:FindFirstChild("BasicBenchPressWeights")
if motor6D and weightModel then
SomeEvent:FireServer(motor6D, weightModel)
end
end)
Server Script
SomeEvent.OnServerEvent:Connect(function(player, motor6D, weightModel)
motor6D:Destroy()
weightModel:Destroy()
end)
I prefer the first method, incase you need to do anything to the character or the objects before destroying. Make sure to actually replace “SomeEvent” with a remote event if you do this. As for the Server Script portion, you can just add this to the same script where you add the objects into the character.
If you have any questions about anything, let me know.