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

How can I make a part follow my mouse? (an attack)

So what I did was make a local script and a remote event and a server script.

Local Script:

local rp = game:GetService("ReplicatedStorage")
local player = game:GetService("Players").LocalPlayer
local Mouse = player:GetMouse()

	Mouse.Move:Connect(function()
		local MousePosition = Mouse.Hit.p
		rp.RemoteEvent:FireServer(Mouse.Hit.p)
	end)

Server Script:

local rp = game:GetService("ReplicatedStorage")
local event = rp:WaitForChild("water")
local mouse = rp:WaitForChild("mouse")

rp.RemoteEvent.OnServerEvent:Connect(function(player,mp)
	print(player)
	print(mp)
	player.Character.Cylinder.Position = Vector3.new(mp)
end)

the player.Character.Cylinder part is when a water cylinder attack's parent is set to the character, and then i try to put its position (vector3) to the mouse position (mp). All that happens is the water cylinder attack just appears in a weird position and doesn't move. No Errors. Please help!

1 answer

Use CFrame instead of .position. I am not sure why that occurs with .position, but all I know is that you need to use CFrame.

This would be your serverscript!

local rp = game:GetService("ReplicatedStorage")
local event = rp:WaitForChild("water")
local mouse = rp:WaitForChild("mouse")

rp.RemoteEvent.OnServerEvent:Connect(function(player,mp)
	print(player)
	print(mp)
	player.Character.Cylinder.CFrame = mp
end)

And this your localscript:

local rp = game:GetService("ReplicatedStorage")
local player = game:GetService("Players").LocalPlayer
local Mouse = player:GetMouse()

    Mouse.Move:Connect(function()
        local MousePosition = Mouse.Hit
        rp.RemoteEvent:FireServer(MousePotition)
    end)

1 comment

0

it works, but the only problem is the cylinder rotates weirdly. How can I make it so that it stays straight up? Also, you did (MousePotition) but i fixed the spelling mistake.

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