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

Can I use a global variable for my script?

Asked by 7 years ago

So I have a shop GUI. The problem is that I wonder if I could use a global variable or I could combine two scripts. My case is like that: in the shop GUI I have a button to buy a super power. The super power is activated when I press the q button for example. Should I combine the two scripts or make a global variable? Or should I make something different? And Hou should I lock the super power script so that only after buying it cand be used by pressing q?

1 answer

Log in to vote
0
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
7 years ago
Edited 7 years ago

Clone the superpower LocalScript into the client's StarterGear and Backpack upon clicking the gui. Have it disabled and enable it upon cloning.

Would look like this:

local plr = game.Players.LocalPlayer;
local super_power = script.Parent:WaitForChild("Superpower1");

script.Parent.MouseButton1Down:Connect(function()
    --If they don't already own it
    if not plr.StarterGear:FindFirstChild(super_power.Name) then
        local c1 = super_power:Clone(); --Clone it
        local c2 = super_power:Clone();
        c1.Parent = plr.StarterGear; --Into startergear(for respawns)
        c2.Parent = plr.Backpack; --Into backpack(for rn)
        c1.Disabled = false; --Enable code
        c2.Disabled = false;
    end
end)
0
Oh thx! tecady2111 12 — 7y
Ad

Answer this question