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

[Solved] How to make a textbutton clone if a players value == the name of a textbutton?

I am working on a weapon inventory gui, but the button doesnt seem to be cloning into the frame.

--Main
local player = game.Players.LocalPlayer
local gui = script.Parent
local rs = game.ReplicatedStorage
local folder = rs:WaitForChild("Buttons")

--Player Values
local gun1 = player:FindFirstChild("gun1")
local gun2 = player:FindFirstChild("gun2")

--Setting Buttons
if gun1 then
	button = folder:FindFirstChild(gun1.Value)
	if button then
		button:Clone().Parent = gui
	end
end

4 comments

1

sir you can not put numbers n a variable with letters

0

ok but even without doing that it still doesnt work

0

You know you’re trying to clone a value? Is gun1 an item or just a string value?

0

Gun 1 is a string

2 answers

Your mistake is that you're cloning a property and not the actual value. Here's the fix in that part of the script:

if gun1 then
	button = folder:FindFirstChild("gun1") -- Fix
	if button then
		button:Clone().Parent = gui
	end
end

1 comment

0

Doest work still.

Ok I figured it out, instead of using :FindFirstChild() I had to use [gun1.Value] and check if nil.

--Main local player = game.Players.LocalPlayer local gui = script.Parent local rs = game.ReplicatedStorage local folder = rs:WaitForChild("Buttons")

player:WaitForChild("gun1")

--Player Values local gun1 = player:FindFirstChild("gun1")

--Setting Buttons if gun1 then button = folder[gun1.Value] if button then button:Clone().Parent = gui end end

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