Ad
Log in to vote
0

I'm trying to replicate a part from the client to the server how would I do that?

Asked by 1 year ago

So the part gets created on the client after that I fire a remote event with the Cframe and size but the part ends up super small and not the right cframe here's the script on the client

local UIS = game:GetService("UserInputService")
local RunService = game:GetService("RunService")

local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Mouse = Player:GetMouse()

local Counter = 1
local Grid = 4
local Toggle = false

local PointA = script.Point:Clone()
local PointB = script.Point:Clone()

local PosA
local PosB
local LRA

function Round(Num, To)
    return math.floor(Num / To + 0.5) * To
end

RunService.RenderStepped:Connect(function()
    if Toggle then
        if Counter == 1 then
            PointA.Parent = workspace
            PosA = Vector3.new(Round(Mouse.Hit.p.X, Grid), .5, Round(Mouse.Hit.p.Z, Grid))
            PointA.CFrame = CFrame.new(PosA) + Vector3.new(0,5,0)
            PointA.Orientation = Vector3.new(0, 90, -90)
        elseif Counter == 2 then
            PointB.Parent = workspace
            PosB = Vector3.new(Round(Mouse.Hit.p.X, Grid), .5, Round(Mouse.Hit.p.Z, Grid))
            PointB.CFrame = CFrame.new(PosB) + Vector3.new(0,5,0)
            PointB.Orientation = Vector3.new(0, 90, -90)

            if LRA then
                LRA:Destroy()
                LRA = nil
            end

            local Mag = (PosA - PosB).magnitude

            local ray = Ray.new(PosA, (PosA - PosB).unit * Mag)
            local part, position = workspace:FindPartOnRay(ray, workspace.Baseplate, false, true)

            local beam = Instance.new("Part", workspace)
            beam.BrickColor = BrickColor.new("Bright yellow")
            beam.FormFactor = "Custom"
            beam.Material = "Neon"
            beam.Transparency = 0.25
            beam.Anchored = true
            beam.Locked = true
            beam.CanCollide = false

            local distance = (PosA - position).magnitude
            beam.Size = Vector3.new(0.3, 10, distance)
            beam.CFrame = CFrame.new(PosA, position) * CFrame.new(0, 0, distance / 2) + Vector3.new(0,5,0)
            LRA = beam
        end
    end
end)

Mouse.Button1Down:Connect(function()
    if Toggle then
        if Counter == 1 then
            Counter = 2
        elseif Counter == 2 then
            Counter = 1
            local Mag = (PosA - PosB).magnitude

            local ray = Ray.new(PosA, (PosA - PosB).unit * Mag)
            local part, position = workspace:FindPartOnRay(ray, workspace.Baseplate, false, true)

            local beam = Instance.new("Part", workspace)
            beam.BrickColor = BrickColor.new("Medium stone grey")
            beam.FormFactor = "Custom"
            beam.Material = Enum.Material.SmoothPlastic
            beam.Transparency = 0
            beam.Anchored = true
            beam.Locked = false
            beam.CanCollide = true

            local distance = (PosA - position).magnitude
            beam.Size = Vector3.new(0.3, 10, distance) + Vector3.new(0,0,.25)
            beam.CFrame = CFrame.new(PosA, position) * CFrame.new(0, 0, distance / 2) + Vector3.new(0,5,0)
            wait(1)
            game.ReplicatedStorage.bulid:FireServer(beam.CFrame, beam.Size)
            LRA:Destroy()
            PointA:Destroy()
            PointB:Destroy()
            PointA = script.Point:Clone()
            PointB = script.Point:Clone()
        end
    end
end)

script.Parent.MouseButton1Click:Connect(function()
    Toggle = true
end)

UIS.InputBegan:Connect(function(Input)
    if Input.KeyCode == Enum.KeyCode.X then
        script.Parent.Parent.Parent:TweenPosition(UDim2.new(.5,0,.5,0), Enum.EasingDirection.InOut, Enum.EasingStyle.Quart, .1)
        script.Parent.Parent.Parent.Parent.Parent.Button.Visible = true
        LRA:Destroy()
        PointA:Destroy()
        PointB:Destroy()
        PointA = script.Point:Clone()
        PointB = script.Point:Clone()
        Toggle = false
        Counter = 1

    end
end)

server code:

game.ReplicatedStorage.bulid.OnServerEvent:Connect(function(beamclonep,beamclonepc)
    local ab = Instance.new("Part")
    ab.Anchored = true
    ab.BrickColor = BrickColor.new("Medium stone grey")
    ab.FormFactor = "Custom"
    ab.Material = Enum.Material.SmoothPlastic
    ab.Transparency = 0
    ab.Anchored = true
    ab.Locked = false
    ab.CanCollide = true
    ab.Size = Vector3.new(beamclonepc)
    ab.CFrame = CFrame.new(beamclonep)
    ab.Name = "servrereswersare"
    ab.Parent = game.Workspace
end)

How do I fix this?

Answer this question