Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 5 years ago
Edited by User#19524 5 years ago

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

0
Use a code block next time, I'll try to help though. TheOnlySmarts 233 — 5y
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. TheOnlySmarts 233 — 5y
0
So if you run this script it means you have to click the button 2 times in order to get your weapon. TheOnlySmarts 233 — 5y
0
thanks, I will try to use these fixes and see what happens imdasupanoob 0 — 5y
View all comments (2 more)
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 User#19524 175 — 5y
0
ok i'm sorry for that imdasupanoob 0 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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 :) **

Ad

Answer this question