Im facing a bug where my weights are being cloned to the Players Right Hand when the player sits in a seat, as usual, but when the Player Leaves the Seat, its intended to destroy the Motor6D and the Model from the Players Right Hand, but for some reason, the 2nd time a player Sits in the Seat it destroys the weights and motor6d but clones it immediatley.
Seat/Destroy Script:
local sitAnim = 18201895983
local seat = script.Parent
local playingAnim
local player = game:GetService("Players"):FindFirstChildOfClass("Player")
local newAnim = Instance.new('Animation')
newAnim.AnimationId = 'rbxassetid://'..sitAnim
seat:GetPropertyChangedSignal("Occupant"):Connect(function()
local Occupant = seat.Occupant
if not Occupant then return end
local Player = game.Players:GetPlayerFromCharacter(Occupant.Parent)
local Character = Occupant.Parent
local rightHand = Character.RightHand
if Occupant and Occupant:IsA("Humanoid") and not playingAnim then
playingAnim = Occupant:LoadAnimation(newAnim)
playingAnim:Play()
elseif Occupant and Occupant:IsA("Humanoid") and playingAnim then
print("Finding weights and motor6D")
local model = rightHand:FindFirstChild("BasicBenchPressWeights")
local motor6D = rightHand:FindFirstChild("BenchpressMotor6D")
model:Destroy()
motor6D:Destroy()
playingAnim:Stop()
playingAnim = nil
end
end)
Cloning Script:
local BenchPressWeights = game.ServerStorage:WaitForChild("BasicBenchPressWeights")
local Prox = script.Parent
Prox.Triggered:Connect(function(player)
local character = player.Character
if not character then
return
end
local humanoid = character:WaitForChild("Humanoid")
local rightHand = character:FindFirstChild("RightHand")
if not rightHand then
return
end
local clone = BenchPressWeights:Clone()
clone.Parent = rightHand
local rightGrip = rightHand:FindFirstChild("RightGrip")
if rightGrip then
rightGrip:Destroy()
end
local Motor6D = Instance.new("Motor6D", rightHand)
Motor6D.Name = "BenchpressMotor6D"
Motor6D.Part0 = rightHand
Motor6D.Part1 = clone.Handle
Motor6D.C0 = CFrame.new(-1.62, 0, 0.03)
end)
I think I’m missing something but are you cloning the parts into the player from a different script? I can’t seem to find where you’re making them appear.
local BenchPressWeights = game.ServerStorage:WaitForChild("BasicBenchPressWeights")
local Prox = script.Parent
Prox.Triggered:Connect(function(player)
local character = player.Character
if not character then
return
end
local humanoid = character:WaitForChild("Humanoid")
local rightHand = character:FindFirstChild("RightHand")
if not rightHand then
return
end
local clone = BenchPressWeights:Clone()
clone.Parent = rightHand
local rightGrip = rightHand:FindFirstChild("RightGrip")
if rightGrip then
rightGrip:Destroy()
end
local Motor6D = Instance.new("Motor6D", rightHand)
Motor6D.Name = "BenchpressMotor6D"
Motor6D.Part0 = rightHand
Motor6D.Part1 = clone.Handle
Motor6D.C0 = CFrame.new(-1.62, 0, 0.03)
end)
Put a seat in studio and checked, the problem is with you detecting if a player is sitting or standing up, just add some print checks to see it, want me to rewrite it for you?
Made changes to both scripts and tested it in studio, works fine (Made it so you only get the weight if you sit through the proximity prompt)
here’s the scripts:
Seat:
local seat = script.Parent
seat:GetPropertyChangedSignal("Occupant"):Connect(function(part)
print("state changed")
local Occupant = seat.Occupant
if Occupant and Occupant:IsA("Humanoid") then
local Player = game.Players:GetPlayerFromCharacter(Occupant.Parent)
local Character = Occupant.Parent
Character.Parent = seat.SeatedPlayer
local rightHand = Character.RightHand
print("Sat down")
elseif Occupant == nil then
print("Stood up")
local charmodel = seat.SeatedPlayer:FindFirstChildOfClass("Model")
charmodel.Parent = workspace
local rightHand = charmodel.RightHand
local model = rightHand:FindFirstChild("BasicBenchPressWeights")
local motor6D = rightHand:FindFirstChild("BenchpressMotor6D")
if model then model:Destroy() end
if motor6D then motor6D:Destroy()end
end
end)
Cloning through the proximity prompt:
local BenchPressWeights = game.ServerStorage:WaitForChild("BasicBenchPressWeights")
local Prox = script.Parent
Prox.Triggered:Connect(function(player)
local character = player.Character
if not character then
return
end
local humanoid = character:WaitForChild("Humanoid")
local rightHand = character:FindFirstChild("RightHand")
if not rightHand then
return
end
workspace.Seat:Sit(humanoid)
local clone = BenchPressWeights:Clone()
clone.Parent = rightHand
local rightGrip = rightHand:FindFirstChild("RightGrip")
if rightGrip then
rightGrip:Destroy()
end
local Motor6D = Instance.new("Motor6D", rightHand)
Motor6D.Name = "BenchpressMotor6D"
Motor6D.Part0 = rightHand
Motor6D.Part1 = clone.Handle
Motor6D.C0 = CFrame.new(-1.62, 0, 0.03)
end)
Add a folder called SeatedPlayer (To put he occupant of the seat into when he’s sitting) into the seat, the animation I’ll take a look at, give me a few minutes please.
The issue is you’re defining the animation track as a local inside of a different function, you can’t retrieve it in the other one, I’d just destroy the animation and create a new one each time a player sits down intead.