Mouse location part rotation is bugged

my video:

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)
4 Likes

No, the mouse location part is correct, it’s the way you are moving the part, which is wrong.

Have you tried in first person?

3 Likes

yes i tried it but still same results…

3 Likes

How are you firing the mouse location event, why is there a while loop inside of the event?

2 Likes

when its doesn’t a loop it just happen one time just with loop its working perfectly but main script is incorrect

mouseposition:

local mousePosition = UserInputService:GetMouseLocation()
2 Likes

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.

2 Likes
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)
2 Likes

There is a ton of problems with this, one of the most important ones is that you are not disconnecting your events.

Why is your input listener inside of an OnClientEvent?

2 Likes

because of this:

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)
2 Likes

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.

2 Likes

how can i fix the mouse location and part rotation i need to know it.

2 Likes

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.

2 Likes

hello, why are you using this to get the position?

from what I read, GetMouseLocation returns the screen location of the mouse in Vector2 form

3 Likes

Like @marix8275 also said, you need to use Mouse.Hit.Position to get a Vector3

3 Likes

Sorry. i dont want mean it i just want the finish this game and publish as most speedy way

2 Likes

what you wanna do is get the mouse position

local mouse = game.Players.LocalPlayer:GetMouse()

then get its world position (which is returned as a cframe), and get the Vector3 position from it

local mousepos = mouse.Hit.Position

and that should fix the mouse position you’re trying to get

2 Likes

i taking this error

2 Likes

is it a local script? it won’t work if it’s a server script

2 Likes

i got it done but im taking still same results

2 Likes

can you show me where the scripts are? in the explorer I mean

2 Likes