So I have this srippt, and you enter a code into a text box and your supposed to get leaderstats from it and it doesnt work and i dont know why please somebody help this is quite urgent thank merry xmas
01 | local box = script.Parent |
02 | local plr = game.Players.LocalPlayer |
03 | local redeemed = false |
04 |
05 | box.FocusLost:connect( function (click) |
06 | if box.Text = = "Test" and redeemed = = false then |
07 | local player = game.Players:GetPlayerByUserId(click.PlayerId) |
08 | player.leaderstats.Bills.Value = player.leaderstats.Bills.Value + 70 |
09 | redeemed = true |
10 | box.Text = "Code Accepted!" |
11 | wait( 1 ) |
12 | box.Text = "Redeem Code" |
13 | elseif box.Text = = "Test" and redeemed = = true then |
14 | box.Text = "Already Used!" |
15 | wait( 1 ) |
why does this have 3 upvotes, i didnt even send an explanation wow
01 | local box = script.Parent |
02 | local plr = game.Players.LocalPlayer |
03 | local redeemed = false |
04 |
05 | box.FocusLost:connect( function () |
06 | if box.Text = = "Test" and redeemed = = false then |
07 | local player = game.Players:GetPlayerByUserId(plr.UserId) |
08 | player.leaderstats.Bills.Value = player.leaderstats.Bills.Value + 70 |
09 | redeemed = true |
10 | box.Text = "Code Accepted!" |
11 | wait( 1 ) |
12 | box.Text = "Redeem Code" |
13 | elseif box.Text = = "Test" and redeemed = = true then |
14 | box.Text = "Already Used!" |
15 | wait( 1 ) |
Do not do this by the client. That's how you get your game exploited and how people develop infinite cash exploits.
Local script:
01 | local box = script.Parent |
02 | local plr = game.Players.LocalPlayer |
03 | local redeemed = false |
04 |
05 | box.FocusLost:connect( function (click) |
06 | local result = game.ReplicatedStorage.TwitterCode:InvokeServer(box.Text) |
07 | if result = = "valid & entered" then -- from here you can add the rest of your code system if you like |
08 | redeemed = true |
09 | box.Text = "Code Accepted!" |
10 | wait( 1 ) |
11 | box.Text = "Redeem Code" |
12 |
13 | else |
14 | -- sample |
15 | end |
16 | end |
Create a remote function, put it in replicated Storage and title it accordingly.
Then add a server script to ServerScriptService:
1 | game.ReplicatedStorage.TwitterCode.OnServerInvoke = function (plr, code) |
2 | if code = = "Test" then -- doing an extra check for no reason but why not |
3 |
4 | game.Players [ plr.Name ] .leaderstats.Bills.Value = game.Players [ plr.Name ] .leaderstats.Bills.Value + 70 |
5 | return "valid & entered" |
6 | end |
7 | end |