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

I have a GUI that wont add a weapon to the players backpack. Why wont it work?

I have a sword in lighting and have this as a local script in a text button

local button = script.Parent
	button.Selected = true
local player = game.Players.LocalPlayer
local starterSword = game.lighting.ClassicSword
 function onClicked()
	if button.Selected == false then
		script.Parent.Parent.Parent.Enabled = false	
		local playersword = starterSword:Clone()
		playersword.Parent = player.Backpack
		button.Selected = true
	elseif		
		button.Selected = false
	end
end

This is my script but nothing happens

6 comments

0

Use a code block next time, I'll try to help though.

0

Why is your Lighting not spelt with a capital L? This doesn't work because at your end line, you're doing an elseif function without adding then, change your elseif line to, 'else button.Selected = false'. Basically the elseif is starting a whole new statement, that's why we're going to use else.

0

So if you run this script it means you have to click the button 2 times in order to get your weapon.

0

thanks, I will try to use these fixes and see what happens

0

I put your code in a codeblock. It is expected that you do this yourself next time. https://forum.scriptinghelpers.org/topic/82/how-to-format-questions-answers-on-the-main-site

0

ok i'm sorry for that

1 answer

You had a few simple mistakes in your script, so I fixed it for you! Here is the result:

local button = script.Parent
button.Selected = true
local player = game.Players.LocalPlayer
local starterSword = game.Lighting.ClassicSword
	function onClicked()
		if button.Selected == false then
			script.Parent.Parent.Parent.Enabled = false 
	        	local playersword = starterSword:Clone()
	        	playersword.Parent = player.Backpack
	        	button.Selected = true
		else    
			button.Selected = false
		end
	end
end

**If this worked, accept the answer, so we both can get reputation :) **

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