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

:Clone() does not work with Weapons? (Gui) a button that when you click you get a weapon...

i made this code that will give a sword to a player when they press a Button but it seems to me that when they press the button you get a sword but the sword does not work??

*Does not hit an enemy

Code

local Sword = script.Parent.ClassicSword
local Button = script.Parent
local Plr = game.Players.LocalPlayer

Button.MouseButton1Click:Connect(function()
	Sword:Clone().Parent = Plr.Backpack -- Sword:Clone() makes it not work????
	Button.Visible = false
	
	
end)

1 answer

Don't do it like this, use a remote event in replicated storage, then have a server connection in serverscriptservice that has something like this:

local RepStore = game:GetService("ReplicatedStorage")
local remote = RepStre:WaitForChild("GiveSword")
local SerStore = game:GetService("ServerStorage")
local toolfolder = game.ServerStorage:WaitForChild("SwordFolder")
local toolstorage = {}
for i, tool in pairs(toolfolder:GetChildren()) do
	table.insert(toolstorage, tool:clone())
end


remote.OnServerConnect(function(player)
	for i, tool in pairs(toolstorage) do
		local newtool = tool:clone()
		newtool.Parent = player.Backpack
	end
end)

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