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

Twitter Redeem Code How-To, left script I made?

Asked by
Jxemes 75
7 years ago

I'm currently making a script for redeeming codes to get a knife or cash. I'm trying to execute it by testing with knife first (if I can correctly do knife, I can do cash) But when I type in the code, It won't work. Anyone got tips of how to fix this?

01local player = game.Players.LocalPlayer
02local shop = player.PlayerGui.ShopGUI.ShopMaster
03local codepage = shop.Pages.Codes
04local codebox = codepage.CodeFrame.Code
05 
06function onActivated()
07    if codebox.Text == "Code1" then
08        game.ReplicatedStorage.Knives.CodeKnife:clone().Parent = player.Backpack
09    end
10end
11 
12codebox.Changed:connect(function(onActivated)

BTW, can I also change "onActivated" to something else that is not global?

1 answer

Log in to vote
1
Answered by 7 years ago

An simple fix is you add a Button called Submit or Enter so that every time it is clicked, it checks the text and if the text is correct then it gives the player whatever the code gives, for example;

This is the positions;

--------------StarterGui -----------ScreenGui ---------TextBox ---------SubmitButton(TextButton) -------LocalScript

This means StarterGui is the main parent, then screen Gui and inside of ScreenGui you have a TextBox and a button and inside of button you have the local script which is the controller,

Now code;

01local Plr = game.Players.LocalPlayer
02local shop = script.Parent.Parent.Parent:WaitForChild('ShopGUI').ShopMaster -- This line may have to be changed
03local SB = script.Parent -- SubmitButton
04local CB = SB.Parent:WaitForChild('TextBox') -- change the name to whatever you named your textbox
05local Code = 'Code1' -- change this to your code
06local CodeKnife = game.ReplicatedStorage.Knives:WaitForChild('CodeKnife')
07 
08SB.MouseButton1Down:Connect(function() -- functions on click
09    if CB.Text == Code then
10        CodeKnife:Clone()
11        CodeKnife.Parent = Plr.Backpack
12    end
13end)

Make sure you have all Gui Objects and change what is necessary. If you followed along and did everything then it should work, if it doesn't work comment the error or fix it if you can.

:WaitForChild() waits for the child to load in so that it would work in both studio and game.

If this helped then please accept answer ;)

Good luck and have fun developing!

0
Works well! Thanks! Jxemes 75 — 7y
0
No problem BlackOrange3343 2676 — 7y
Ad

Answer this question