Clone from server storage

I am very new at cloning in Replicated Storage, how would I clone a part that is in the storage in front of the player when game is started?

1 Like

Well, what you could do is implement a PlayerAdded & event which will fire as soon as a Player joins the game

And inside that Event, we can go ahead & clone our Part that’s inside our ReplicatedStorage Service and position it in front of the player using a LookVector:

game.Players.PlayerAdded:Connect(function(Player)
    local HRP = Player.Character:WaitForChild("HumanoidRootPart")

    local ClonedPart = game.ReplicatedStorage.Part:Clone()
    ClonedPart.Parent = workspace
    ClonedPart.Position = HRP.CFrame.LookVector * 5
end)
1 Like

how would i do it so that it would clone by pressed key?
like this?

local UIS = game:GetService("UserInputService")
local Character = script.Parent
local Npc = game.Workspace.Npc
local camera = workspace.CurrentCamera
local Player = game.Players.LocalPlayer

UIS.InputBegan:Connect(function(Key, Chatted)
	if Chatted then
		return
	end
	local Player = game.Players.LocalPlayer
	if Key.KeyCode == Enum.KeyCode.E then
local HRP = Player.Character:WaitForChild("HumanoidRootPart")

    local ClonedPart = game.ReplicatedStorage.Part:Clone()
    ClonedPart.Parent = workspace
    ClonedPart.Position = HRP.CFrame.LookVector * 5
end)

Then you would have a local script that detects the user input, makes sure it’s pressing the intended key, and then you fire a remote event which you handle on the server (if you want every player to see it). If it’s just there as an effect, you can do it through the client but it will not affect other players or the game.

Also you’re referencing the Player variable twice, remove the one you have inside your InputBegan event

how would i detect that the player have only one part cloned? i just want the player have one clone part forever

local UIS = game:GetService("UserInputService")
local Character = script.Parent
local HRP = Character:WaitForChild("HumanoidRootPart")
local Npc = game.Workspace.Npc
local camera = workspace.CurrentCamera
local CurrentParts = 0

UIS.InputBegan:Connect(function(Key, Chatted)
	if Chatted and CurrentParts >= 1 then
		return
	end

	if Key.KeyCode == Enum.KeyCode.E then
        local ClonedPart = game.ReplicatedStorage.Part:Clone()
        ClonedPart.Parent = workspace
        ClonedPart.Position = HRP.CFrame.LookVector * 5
        CurrentParts += 1
    end
end)

This would only be done on the client side however, you can do this on the server side as well if this is parented inside StarterCharacterScripts to prevent exploiters

does that mean that only the player can see it? how would i make it so that everyone sees it

Learn about Server-side and Client-side communication: Bindable Events and Functions | Roblox Creator Documentation

You’ll need to use Remote events for everyone to be able to see what you cloned locally.

You’d need to fire a RemoteEvent which would handle client-server transportation, to send the request to create the Part on the server side

That’ll mean you’d also need to create a ServerScript inside ServerScriptService:

local UIS = game:GetService("UserInputService")
local Character = script.Parent
local Npc = game.Workspace.Npc
local camera = workspace.CurrentCamera
local Event = game.ReplicatedStorage:WaitForChild("RemoteEvent")
local CurrentParts = 0

UIS.InputBegan:Connect(function(Key, Chatted)
	if Chatted and CurrentParts >= 1 then
		return
	end

	if Key.KeyCode == Enum.KeyCode.E then
        CurrentParts += 1
        Event:FireServer()
    end
end)
--ServerScript
local Event = game.ReplicatedStorage:WaitForChild("RemoteEvent")

Event.OnServerEvent:Connect(function(Player)
    local Character = Player.Character
    local HRP = Character:WaitForChild("HumanoidRootPart")

    local ClonedPart = game.ReplicatedStorage.Part:Clone()
    ClonedPart.Parent = workspace
    ClonedPart.Position = HRP.CFrame.LookVector * 5
end)
3 Likes

oh god im sorry for asking you for scripts i should’ve take my time to learn more

You’re fine :sweat_smile: But yeah please do take the time to learn more about this kind of information, especially learning how they can work


theres some errors ;-;

You have to insert a RemoteEvent Object inside the ReplicatedStorage Service, also there’s no Npc located inside the workspace

uhhhhhh it did not spawn in front of the player ;-;
and this:


and my dragging system don’t work on the dummie

You still have to account for the other error as well

already done(btw the dragging does work now but there is no dummie limit)

found the error lol

Why the heck is a Part a Model

Use the MoveTo() function inside the Server Script:

--ServerScript
local Event = game.ReplicatedStorage:WaitForChild("RemoteEvent")

Event.OnServerEvent:Connect(function(Player)
    local Character = Player.Character
    local HRP = Character:WaitForChild("HumanoidRootPart")

    local ClonedPart = game.ReplicatedStorage.Part:Clone()
    ClonedPart.Parent = workspace
    ClonedPart:MoveTo(HRP.CFrame.LookVector * 5)
end)

…it spawned at the spawn + the spam of this again

I fixed the spammy thing but the dummies don’t spawn in my face