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

How to clone part with scripts from server storage?

Asked by
TechModel 118
3 years ago
Edited 3 years ago

This tool spawns a vehicle that clones it from ServerStorage, but it's a local script and It cant clone anything from the Server so I tried using a remote event with a server script located in serverscriptservice. I get errors like can't get the mouse (Cframe is not valid member of CFrame) and when I spaw the clone part and destroy it, The Parent Property is locked. This is a mess but if there's a video on this topic or another question by someone, then I'd love to check it out

local Remote = game:GetService("ReplicatedStorage"):WaitForChild("SpawnVehicle")
local Vehicle = game.ServerStorage.Limbo:Clone()

Remote.OnServerEvent:Connect(function(plr, mouse)
    Vehicle:Clone()
    Vehicle.Parent = workspace
    Vehicle:SetPrimaryPartCFrame(mouse.CFrame)
end)

(EDIT) And here is the local script parented in the tool:

local plr = game.Players.LocalPlayer
local char = workspace:FindFirstChild(plr.Name)
local mouse = plr:GetMouse()
local Equipped = false

script.Parent.Equipped:Connect(function()
    if not Equipped then
    Equipped = true
        local Circle = game.ReplicatedStorage.PartsPreview:WaitForChild("Circle"):Clone()
        Circle.Parent = workspace
        mouse.TargetFilter = Circle
        mouse.Move:Connect(function()
        local posX,posY,posZ = mouse.Hit.X,mouse.Hit.Y,mouse.Hit.Z
        Circle:MoveTo(Vector3.new(posX,posY,posZ))
      end)

script.Parent.Activated:Connect(function()
            if Equipped then
                if Circle.PrimaryPart then
                    --[[local PartPlacement = game.ReplicatedStorage.Parts:WaitForChild("Limbo"):Clone()
                    PartPlacement.Parent = workspace
                    PartPlacement:SetPrimaryPartCFrame(Circle.PrimaryPart.CFrame)]]
                    local remote = game:GetService("ReplicatedStorage"):WaitForChild("SpawnVehicle")
                    remote:FireServer()
                end
            end
end)
0
Can we see your local script? DietCokeTastesGood 111 — 3y
0
Apologies. Updated the question. TechModel 118 — 3y

Answer this question