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

How could I make this script make its parent move to the players mouse click?

game.Players.PlayerAdded:Connect(function(plr)
	local Mouse = plr:GetMouse()
	Mouse.Button1Down:Connect(function()
	script.Parent:MoveTo(Mouse.Hit.p)
	end)
end)

Also, I don't understand why I am getting this error - Workspace.Moving.Script:4: attempt to index local 'Mouse' (a nil value)

1 comment

0

You cant use Mouse in server script

1 answer

✓ Accepted answer

You can't get a player's Mouse using a Server Script, you should use a LocalScript to get the Player's Mouse

but if you use a LocalScript, it wont replicate to other players so you would need to pass Information from a LocalScript to a Server Script using RemoteEvents

LocalScript (StarterPlayerScripts)

local Player = game:GetService("Players").LocalPlayer
local Remote = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent")
local Mouse = Player:GetMouse()

Mouse.Button1Down:Connect(function()
	local Model = --The Model you wanna Move
	Remote:FireServer(Mouse.Hit.p, Model)
end)

Server Script (ServerScriptService)

local Remote = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent")

Remote.OnServerEvent:Connect(function(player, MousePosition, Object)
	Object:MoveTo(MousePosition)
end)

2 comments

0

I am getting this error - MoveTo is not a valid member of Part

0

@jalbraek oh, i thought you we're trying to move a model, so you should change the part's CFrame instead

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