Help with script.Disabled

Hi! I’m making a “plane” that will point to the direction the mouse is, and it works fine. But there is ONE problem: when you join the game, it points at the mouse when your not touching the VehicleSeat. I’m really annoyed this happens, so I need some help.
First, it’s a local script inside StarterPlayerScripts.
Second, here is the code:

local plane = workspace.Model.PlaneBody
local player = game:GetService("Players").LocalPlayer
local mouse = player:GetMouse()
local mouseActive = game.StarterPlayer.StarterPlayerScripts.FollowMouse.Disabled == true
if mouseActive == false then
	mouse.Move:connect(function()
		local mousePosition = mouse.Hit.p
		plane.CFrame = CFrame.new(plane.CFrame.p,mousePosition)
	end)
end

So, how do I make it so when I touch the VehicleSeat, the script will enable and follow the mouse, and when I stop touching it, how do I make it disable the script?
Thanks.

1 Like

Maybe try not making it a local statement, see if that works.

This won’t work. The script is located under player.PlayerScripts, not under StarterPlayer.StarterPlayerScripts. Also shouldn’t it just be the Disabled value? Why there’s a == true?

Alright so, I’ll point one thing out first, that’s a local script so it will not replicate to other clients meaning others will not see the plane flying. Learn about filtering enabled and remote events.

Second, you can check if player is sitting on seat by checking if a weld is added to seat or not and who it is welded to.

Hey, it at least WORKS. First, it gives me an error without the ==, second player.PlayerScripts has been already tried, and third, I don’t know how to disable a local script so there.

Instead of checking if it is disabled once, check every time the mouse is moved.

local plane = workspace.Model.PlaneBody
local player = game:GetService("Players").LocalPlayer
local mouse = player:GetMouse()
mouse.Move:connect(function()
	if game.StarterPlayer.StarterPlayerScripts.FollowMouse.Disabled == true then
		local mousePosition = mouse.Hit.p
		plane.CFrame = CFrame.new(plane.CFrame.p,mousePosition)
	end
end)

Use Seat.ChildAdded:Connect and Seat.ChildRemoved:Connect to start and stop your code.

How would I do that @Sir_Highness, as I’m using Kaid3n22’s code (above your reply.)

mouse.Move:connect(function()
	if game.StarterPlayer.StarterPlayerScripts.FollowMouse.Disabled == true then
		local mousePosition = mouse.Hit.p
		plane.CFrame = CFrame.new(plane.CFrame.p,mousePosition)
	end
end)

I"m not sure, I don’t understand what your script is doing, or what the ‘followmouse’ script is or how you expect it to become disabled or enabled.

I think for the seat connection to work it would probably have to be a server script vs a localscript so then you’d need two scripts and possibly remote events, so, I don’t know. But you can use seat.ChildAdded:Connect in a server script to ‘do something’ when someone sits in a seat, I have done that.

Here is a tutorial for using seat.ChildAdded:

1 Like

Thank you so much! This helped me finish this project a little more!