Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Clone part from ReplicatedStorage to Workspace?

I wanna clone part from ReplicatedStorage to Workspace now the code that i have already works But i want the value like

Local player for example BolfstarPrimraryW

And i want the code on click you can add and remove the clone

local Glass = game.ReplicatedStorage.Glass


local playerservice = game:GetService("Players")
local player = workspace

script.Parent.MouseButton1Click:connect(function()
	Glass:Clone().Parent = game.Players.LocalPlayer
	game.Workspace.Glass.Name = player.name
end)

1 comment

0

you should put the Glass:Clone().Parent = game.Players.LocalPlayer.Character

2 answers

✓ Accepted answer

Just come up with some code: Not sure if it will work online but it works in the studio.

local Glass = game.ReplicatedStorage.Glass:Clone() -- Clone  the glass when this script loads

local playerservice = game:GetService("Players")
local player = playerservice.LocalPlayer

local Glass_Active = false -- Toggle for show/hiding the Glass
local UserGlass = nil -- User Glass, This is set below!

script.Parent.MouseButton1Click:connect(function()
	if(Glass_Active == false) then -- If the user has no glass create one!
		Glass_Active = true
		if(UserGlass == nil) then
			UserGlass = Glass:Clone()
			UserGlass.Parent = workspace
		end
		UserGlass.Name = player.Name
	else -- the user already has a Glass then lets put it away!
		Glass_Active = false
		if(UserGlass ~= nil) then -- Check to see if our UserGlass isn't allready equal nil
			UserGlass:Destroy()
			UserGlass = nil
		end
	end
end)

1 comment

0

Thank you! The script works in studio not tested yet in online but now i'm working on a class system so that if a player select for example (Mp5) That gun will be selected for Primrary gun and the attachments will be loaded if the player press deploy but for dis system i use dis script so that the local player can view the gun and change the attachements/color

local Glass = game.ReplicatedStorage.Glass


local playerservice = game:GetService("Players")
local player = playerservice.LocalPlayer

script.Parent.MouseButton1Click:connect(function()
	Glass:Clone().Parent = workspace
	game.Workspace.Glass.Name = player.Name
end)

Wrong code sorry!

1 comment

0

hmm what kinda like a toggle? aka Click once it clones then click again it removes?, Ill see what i can come up with

This discussion is preserved as it was. New answers, comments, and votes are closed.