I am checking and made a code review so a pro can improve my scripting skill. Here is the script:
local debounce = false
script.Parent.Touched:Connect(function(Touched)
if not debounce then
debounce = true
if Touched.Parent:FindFirstChild("Humanoid") then
wait(.5)
if not script.Parent:FindFirstChildOfClass("Motor6D") then
Instance.new("Motor6D",script.Parent)
script.Parent.Motor6D.Part0 = script.Parent
script.Parent.Motor6D.Part1 = Touched.Parent.HumanoidRootPart
script.Parent.Motor6D.C1 = CFrame.new(0, -1.5, 0)
Touched.Parent.Humanoid.Sit = true
end
wait(1)
if Touched.Parent.Humanoid.Sit == false then
script.Parent:FindFirstChildOfClass("Motor6D").Part1 = nil
end
wait(5)
debounce = false
end
end
end)
I don’t use seat. I will use Motor6D to lock my humanoidrootpart to the ‘seat’
4 Likes
You can debug at different parts to know when the script breaks by printing many times. Maybe try this and go to the output and see the last number it prints. That means between the last number printed and the number after that is the error. Anyways I will debug it for you u just gotta copy and paste here:
local debounce = false
script.Parent.Touched:Connect(function(Touched)
if not debounce then
debounce = true
print (1)
if Touched.Parent:FindFirstChild("Humanoid") then
wait(.5)
if not script.Parent:FindFirstChildOfClass("Motor6D") then
Instance.new("Motor6D",script.Parent)
script.Parent.Motor6D.Part0 = script.Parent
script.Parent.Motor6D.Part1 = Touched.Parent.HumanoidRootPart
script.Parent.Motor6D.C1 = CFrame.new(0, -1.5, 0)
Touched.Parent.Humanoid.Sit = true
end
print(2)
wait(1)
if Touched.Parent.Humanoid.Sit == false then
script.Parent:FindFirstChildOfClass("Motor6D").Part1 = nil
end
wait(5)
print (3)
debounce = false
end
end
end)
5 Likes
You can add more prints to debug it further
4 Likes
when i jump, the humanoidrootpart is still locked to the seat.
1 Like
ok I just fixed it
local debounce = false
script.Parent.Touched:Connect(function(Touched)
if not debounce then
debounce = true
print (1)
if Touched.Parent:FindFirstChild("Humanoid") then
wait(.5)
if not script.Parent:FindFirstChildOfClass("Motor6D") then
Instance.new("Motor6D",script.Parent)
script.Parent.Motor6D.Part0 = script.Parent
script.Parent.Motor6D.Part1 = Touched.Parent.HumanoidRootPart
script.Parent.Motor6D.C1 = CFrame.new(0, -1.5, 0)
Touched.Parent.Humanoid.Sit = true
end
print(2)
wait(1)
if Touched.Parent.Humanoid.Changed then
script.Parent:FindFirstChildOfClass("Motor6D"):Destroy()
end
wait(5)
print (3)
debounce = false
end
end
end)
2 Likes
Wait. It’s not fixed. The motor6d actually is removed when I press W or A or S or D