How do I make this server side

Hello, so I’m making a wand and I’ve made this script for it to work on the players client. And I’m confused on how to make it serversided

` local Wand = script.Parent
local player = game:GetService(“Players”).LocalPlayer
Wand.Equipped:Connect(function(mouse)
mouse.Button1Down:Connect(function()
local ray = Ray.new(Wand.BeamParent.CFrame.p, (mouse.Hit.p - Wand.BeamParent.CFrame.p).unit * 300)
local part, position = workspace:FindPartOnRay(ray, player.Character, false, true)
local beam = Instance.new(“Part”, workspace)
beam.BrickColor = BrickColor.new(“Royal purple”)
beam.Material = “Neon”
beam.Transparency = 0.25
beam.Anchored = true
beam.Locked = true
beam.CanCollide = false

    local distance = (Wand.BeamParent.CFrame.p - position).magnitude
    beam.Size = Vector3.new(0.3, 0.3, distance)
    beam.CFrame = CFrame.new(Wand.BeamParent.CFrame.p, position) * CFrame.new(0, 0, -distance / 2)
    if part then
        local humanoid = part.Parent:FindFirstChild("Humanoid")
        if not humanoid then
            humanoid = part.Parent.Parent:FindFirstChild("Humanoid")
        end
        if humanoid then
            humanoid:TakeDamage(10)
        end
    end
end)

end)`

you’d want to send over info such as mouse position to the server and have calculations, visuals and takedamage run on the server. i’d suggest using removeevents in this case.

for client-server communication check out this reference on remoteevents.

Alr thanks, I’ll look into it I’m still learning scripting so I might be choppy

btw this is deprecated

hope the links help

Thanks, I’ll also check this out

1 Like

Just a heads-up, workspace:FindPartOnRay is deprecated not Ray.new. Ray is a datatype and it’s completely fine to use it.

1 Like

oh, let me edit my reply then
I thought raycast params removed that too

EDIT:
the reply should be fixed now

1 Like