Need help with missile controlled by players mouse

Hello,

So i’m currently trying to make a missile that is controlled by a player so the player can steer the missile. Now I only came this far cause I don’t really know what to do next. So if anyone could help me with this that would be great.

Script:

local velocity = 100

game.Players.PlayerAdded:Connect(function(player)
	local mouse = player:GetMouse()
	
	local currentCamera = workspace.Camera
	
	local linearVel = script.Parent.LinearVelocity
	local angularVel = script.Parent.AngularVelocity
	
	local nuke = game.Workspace.Nuke
	
	if mouse then
		local mousePos = mouse.Hit.Position
		
		
	end
end)
3 Likes

You can only get the Mouse at the Local script and not at the Server Script

Ok I already knew that but do you know how I can make it so the player can control the missile?

You have to use a local script for Player:GetMouse() and you can’t use the PlayerAdded event on the local player either way.

You need to have a RemoteEvent so the client can send the mouse position to the server.

Alright I now have 2 scripts attached to each other one in the model and one in StarterPlayer. But the main problem isnt solved yet. Which is how can I control the model with my mouse?

Try using AlignPosition and set the missile’s position to Player:GetMouse().Hit.Position. Make sure you do so in a local script and you should probably give NetworkOwnership of the missile to the player that is controlling it.

Can u show me an example of NetWorkOwnership? Also the missile is a model ofcourse so do I set the Position with something like this?

missile.CFrame.Position = mouse.Hit.Position

Don’t use regular position. Actually you could probably just insert a body position into the rocket and use InputBegan to detect when the mouse moves and set the BodyPosition.Position to the mouse.Hit.Position. Put the body position inside the root of the model and weld all the parts of the model to that root.

1 Like

Ok I’ll try that tomorrow and reply after i’ve done it.

Which part is the root part?

image

And how do I check if the mouse is moving cause

if input.UserInputType == Enum.UserInputType.MouseMovement then

isn’t working

local rep = game:GetService("ReplicatedStorage")
local remoteEvent = rep:WaitForChild("RemoteEvent")
local uis = game:GetService("UserInputService")
local nuke = game.Workspace.Nuke

local player = game:GetService("Players").LocalPlayer

local mouse = player:GetMouse()
local mousePosition = mouse.Hit.Position

remoteEvent.OnClientEvent:Connect(function()
	print("step 2")
	uis.InputBegan:Connect(function(input, gameProcessed)
		print("step 3")
		if input.UserInputType == Enum.UserInputType.MouseMovement then
			
			print("step 4")
			local bp = Instance.new("BodyPosition")
			bp.Parent = nuke
			bp.Position = mousePosition
			print("step 5")
		end
	end)
end)

Ok so I changed that script to this:

local rep = game:GetService("ReplicatedStorage")
local remoteEvent = rep:WaitForChild("RemoteEvent")
local uis = game:GetService("UserInputService")
local nuke = game.Workspace.Nuke

local player = game:GetService("Players").LocalPlayer

local mouse = player:GetMouse()
local mousePosition = mouse.Hit.Position

remoteEvent.OnClientEvent:Connect(function()
	print("step 2")
	uis.InputChanged:Connect(function(input, engine_processed)
		print("step 3")
		if engine_processed then
			return
		end
		if input.UserInputType == Enum.UserInputType.MouseMovement then
			print(engine_processed)
			local bp = Instance.new("BodyPosition")
			bp.Parent = nuke
			bp.Position = mousePosition
			print("step 5")
		end		
			
			
		
	end)
end)

and now it prints everytime i move with my mouse but the problem is, is that the nuke still doesn’t moves.

1 Like

Parent the body position to the nuke profile part and then weld all the other parts to the nuke profile

Still doesn’’ t makes the nuke fly I also weld all parts to the profile.

remoteEvent.OnClientEvent:Connect(function()
	print("step 2")
	uis.InputChanged:Connect(function(input, engine_processed)
		print("step 3")
		if engine_processed then
			return
		end
		if input.UserInputType == Enum.UserInputType.MouseMovement then
			print(engine_processed)
			local bp = Instance.new("AlignPosition")
            bp.ApplyAtCenterOfMass = true
            bp.MaxVelocity = 50
            bp.Responsiveness = 200
            bp.Mode = Enum.PositionAlignmentMode.OneAttachment
			bp.Parent = nuke.NukeProfile
			bp.Position = mousePosition
			print("step 5")
		end		
			
			
		
	end)
end)

try this

Doesn’t works either. Does the rocket needs to be unanchored? I just tried to unanchor it but still doesn’t makes the rocket fly with mouse.

@http_shawn