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?
✓ ANSWER ACCEPTED
Can I use a global variable for my script?
1 answer
✓ Accepted answer
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)
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
Oh thx!