Hi, I am trying to make a bench-press but it isn’t working correctly. I’ve tried using events but it would just loop it after you use it once and I’ve tried disabling the script and it didnt work either. The script for detecting when you jump off a seat is in starterplayer > startercharacterscripts. The output repeats infinite yield possible on :waitforchild(). Anybody have a solution?
local plr = game.Players.LocalPlayer
local Char = plr.Character
local Humanoid = Char:FindFirstChild("Humanoid")
local rE = game.ReplicatedStorage.MachineJumpEvent.Jumped
local Gns = plr.Backpack:WaitForChild("Gains")
if Humanoid.sit == true then
if Humanoid.Jump == true then
if plr.Backpack:FindFirstChild("Gains") then
Gns:Destroy()
print("Fired")
end
end
end
Well, if it repeats infinite yield possible on :WaitForChild() and never finishes waiting, that means that no Instance called Gains is added to the player’s backpack. Have you tried putting a print after the WaitForChild() line to see if it actually finds that Instance in the backpack?
Also, your code after that isn’t going to work. Try this instead. I wrote it on phone and haven’t tested it so I’m not sure if it works.
Humanoid.StateChanged:Connect(function(oldState, newState)
if oldState == Enum.HumanoidStatetype.Seated and newState = Enum.HumanoidStatetype.Jumping then
local gains = plr.Backpack:FindFirstChild("Gains")
if gains then
gains:Destroy()
end
end
end)
local Player = game.Players.LocalPlayer
local Char = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Char:WaitForChild("Humanoid")
local rE = game.ReplicatedStorage.MachineJumpEvent.Jumped -- Make sure the the event position is correct.
if Humanoid.Sit == true and Humanoid.Jump == true then
if Player.Backpack:FindFirstChild("Gains") then
Player.Backpack:FindFirstChild("Gains"):Destroy()
print("Fired")
end
end