Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by
lilzy7 68
3 years ago
Edited 3 years ago

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

Log in to vote
0
Answered by
rabbi99 714 Moderation Voter
3 years ago
Edited 3 years ago

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)
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. lilzy7 68 — 3y
Ad

Answer this question