script.Parent.MouseLocation.OnServerEvent:Connect(function(mousePosition)
while true do
wait()
if script.Parent.Engine.Value == true then
script.Parent.Parent.Base.CFrame = CFrame.new(script.Parent.Parent.Base.Position, Vector3.new(mousePosition))
else
break
end
end
end)
It’s not working perfectly, can you provide both your scripts, if the event is only fired once then you are not even getting the mouse position each time the mouse moves, you are only getting one.
script.Parent.Event.OnClientEvent:Connect(function(plr)
local player = plr
local UserInputService = game:GetService("UserInputService")
local mousePosition = UserInputService:GetMouseLocation()
UserInputService.InputBegan:Connect(function(key)
if key.KeyCode == Enum.KeyCode.E then
script.Parent.MouseLocation:FireServer(mousePosition)
script.Parent.EngineEvent:FireServer()
end
while task.wait(1) do
if UserInputService:IsKeyDown(Enum.KeyCode.S) then
script.Parent.SpeedDown:FireServer()
elseif UserInputService:IsKeyDown(Enum.KeyCode.W) then
script.Parent.SpeedUp:FireServer()
end
end
end)
end)
script.Parent.MouseLocation.OnServerEvent:Connect(function(mousePosition)
while true do
wait()
if script.Parent.Engine.Value == true then
script.Parent.Parent.Base.CFrame = CFrame.new(script.Parent.Parent.Base.Position, Vector3.new(mousePosition))
else
break
end
end
end)
local seat = script.Parent
local prompt = seat.ProximityPrompt
local plrs = game:GetService("Players")
local GuiToClone = script.Parent.FighterJetGui
prompt.Triggered:Connect(function(plr)
local char = plr.Character
seat:Sit(char.Humanoid)
prompt.Enabled = false
script.Parent.Event:FireClient(plr)
end)
local formerPlayer
seat:GetPropertyChangedSignal("Occupant"):Connect(function()
local hum = seat.Occupant
if hum then
local player = plrs:GetPlayerFromCharacter(hum.Parent)
prompt.Enabled = false
GuiToClone:Clone().Parent = player.PlayerGui
formerPlayer = player
else
formerPlayer.PlayerGui[GuiToClone.Name]:Destroy()
prompt.Enabled = true
formerPlayer = nil
end
end)
Okay so, inside of your client script, you should have a value instead of checking to put your input listener inside of the OnClientEvent to both save on bandwidth and to not have further problems. Inside the OnClientEvent just set your Occupant value on the client to be true or false, then at the beginning of your InputBegan event just check that value
local Occupant = false;
script.Parent.Event.OnClientEvent:Connect(function(plr)
Occupant = not Occupant;
end)
UserInputService.InputBegan:Connect(function(key)
if not Occupant then return end
end)
Also please stop using while loops like this, this is not how you use them. Especially not inside of events.
I am teaching you useful stuff you should know while helping you, if you don’t want to learn wait for someone to write and paste the code for you, you shouldn’t have a while loop inside of your event that is one of the first reasons why it is broken.