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

Why does my TextButton not give me a sword when I click on it? (gui)

I have a TextButton, and, I want it to add a sword to my backpack when I click on it. The ONLY problem is that when I click on the TextButton, it does not give me my sword. Please help


-- This is inside a TextButton
script.Parent.MouseButton1Click:connect(function()
	local RS = game:GetService("ReplicatedStorage")
	local item = RS:WaitForChild("LinkedSword")
	local player = game.Players.LocalPlayer
	
	local cloned = item:Cloned()
	cloned.Parent = player.Backpack
	
end)

1 comment

0

:WaitForChild("LinkedSword") < That might be the issue.

1 answer

✓ Accepted answer

Cloned is not a method. Clone() is a method. Assuming this is in a localscript and that waitforchild isn't infinite, it should work perfectly fine.

-- This is inside a TextButton
script.Parent.MouseButton1Click:connect(function()
    local RS = game:GetService("ReplicatedStorage")
    local item = RS:WaitForChild("LinkedSword")
    local player = game.Players.LocalPlayer

    local cloned = item:Clone()
    cloned.Parent = player.Backpack

end)

2 comments

0

Well if it isn't a localscript game.Players.LocalPlayer wouldn't work. Good job catching that syntax

0

Thanks, it worked!

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