Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I move a seat when I'm sitting in it?

I'm trying to move a seat when I sit in it. My script isn't working, and isn't giving me an error message.

The following script is supposed to make the seat move by .25 studs every half a second when the script detects a Humanoid is sitting in the seat. The script is inside a seat.

local debounce = false

while true do
	wait(.5)
	if script.Parent.Occupant == "Humanoid" then
		
		if debounce == false then
			debounce = true
			
			while true do
				wait(.5)
				script.Parent.Position = script.Parent.Position - Vector3.new(0,0,.25)
			end
			
		end	
	end
end

1 answer

✓ Accepted answer
local Seat = script.Parent

Seat.Anchored = true
local Check = false

Seat:GetPropertyChangedSignal("Occupant"):Connect(function()
 Check = not Check
   while Check and wait(.5) do
     Seat.CFrame = Seat.CFrame * CFrame.new(0, 0, .25)
   end
end)

-- Place this script inside the seat.
-- Make sure it's an server script.

I hope this helps you, please let me know if it worked!

3 comments

0

It gave me an error :( "Workspace.Object.Seat.Script:4: attempt to index local 'LocalPlayer' (a nil value)"

0

Try now.

0

Yes it worked! Thank you so much

This discussion is preserved as it was. New answers, comments, and votes are closed.