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

Twitter Code GUI Not Giving Leaderstats?

Asked by
Rynappel 212 Moderation Voter
5 years ago

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

01local box = script.Parent
02local plr = game.Players.LocalPlayer
03local redeemed = false
04 
05box.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)
View all 22 lines...
1
It doesn't seem wise to add leaderstats on the client so that's probably why it won't work the way you want, merry xmas CeramicTile 847 — 5y

2 answers

Log in to vote
4
Answered by
raid6n 2196 Moderation Voter Community Moderator
5 years ago
Edited 4 years ago

why does this have 3 upvotes, i didnt even send an explanation wow

01local box = script.Parent
02local plr = game.Players.LocalPlayer
03local redeemed = false
04 
05box.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)
View all 22 lines...
Ad
Log in to vote
0
Answered by
Gojinhan 353 Moderation Voter
5 years ago
Edited 5 years ago

Do not do this by the client. That's how you get your game exploited and how people develop infinite cash exploits.

Local script:

01local box = script.Parent
02local plr = game.Players.LocalPlayer
03local redeemed = false
04 
05box.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:

1game.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
7end
0
There's actually a reason for re-checking, exploiters can call the remote event, its good if you also check if the code was already redeemed on the server Leamir 3138 — 5y
0
Doesnt work, Rynappel 212 — 5y
0
don't just copy and paste it, do try to rework it to fix errors. Gojinhan 353 — 5y
0
What do you think I did? Rynappel 212 — 5y
0
No output, no nothing. Still didnt work Rynappel 212 — 5y

Answer this question