Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Twitter Code GUI Not Giving Leaderstats?

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 comment

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

2 answers

✓ Accepted answer

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)

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

5 comments

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

0

Doesnt work,

0

don't just copy and paste it, do try to rework it to fix errors.

0

What do you think I did?

0

No output, no nothing. Still didnt work

This discussion is preserved as it was. New answers, comments, and votes are closed.