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

local box = script.Parent
local plr = game.Players.LocalPlayer
local redeemed = false

box.FocusLost:connect(function(click)
    if box.Text == "Test" and redeemed == false then
        local player = game.Players:GetPlayerByUserId(click.PlayerId)
        player.leaderstats.Bills.Value = player.leaderstats.Bills.Value + 70
        redeemed = true
        box.Text = "Code Accepted!"
        wait(1)
        box.Text = "Redeem Code"
    elseif box.Text == "Test" and redeemed == true then
        box.Text = "Already Used!"
        wait(1)
        box.Text = "Redeem Code"
    else
        box.Text = "Code Declined!"
        wait(1) 
        box.Text = "Redeem Code"
    end
end)
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


local box = script.Parent local plr = game.Players.LocalPlayer local redeemed = false box.FocusLost:connect(function() if box.Text == "Test" and redeemed == false then local player = game.Players:GetPlayerByUserId(plr.UserId) player.leaderstats.Bills.Value = player.leaderstats.Bills.Value + 70 redeemed = true box.Text = "Code Accepted!" wait(1) box.Text = "Redeem Code" elseif box.Text == "Test" and redeemed == true then box.Text = "Already Used!" wait(1) box.Text = "Redeem Code" else box.Text = "Code Declined!" wait(1) box.Text = "Redeem Code" end end)
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:

local box = script.Parent
local plr = game.Players.LocalPlayer
local redeemed = false

box.FocusLost:connect(function(click)
        local result = game.ReplicatedStorage.TwitterCode:InvokeServer(box.Text)
    if result == "valid & entered" then -- from here you can add the rest of your code system if you like
        redeemed = true
             box.Text = "Code Accepted!"
             wait(1)
             box.Text = "Redeem Code"

        else
            -- sample
        end
    end

Create a remote function, put it in replicated Storage and title it accordingly.

Then add a server script to ServerScriptService:

game.ReplicatedStorage.TwitterCode.OnServerInvoke = function(plr, code)
    if code == "Test" then -- doing an extra check for no reason but why not

    game.Players[plr.Name].leaderstats.Bills.Value = game.Players[plr.Name].leaderstats.Bills.Value + 70             
    return "valid & entered"
    end
end
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