I’m having an issue some codes work and you can redeem them multiple times.
ServerScriptService Script:
RemoteEvent.OnServerEvent:Connect(function(Player, Reward, Code)
if Player:FindFirstChild(Code) == nil then
local Redeemed = Instance.new("BoolValue", Player)
Redeemed.Name = Code
Redeemed.Value = false
if Redeemed.Value == false then
Player.leaderstats.Cash.Value += Reward
Redeemed.Value = true
end
end
end)
-------------------------------------------------------------------------
Code In Frame
-------------------------------------------------------------------------
```local Codes = {"SomeOddYtber","HoonIsCat","RELEASE!"}
local RemoteEvent = game.ReplicatedStorage.CodeEvent
script.Parent.EnterButton.MouseButton1Click:Connect(function()
if script.Parent.InputBox.Text == Codes[1] then
RemoteEvent:FireServer(100, Codes[1])
else
if script.Parent.InputBox.Text == Codes[2] then
RemoteEvent:FireServer(100, Codes[2])
else
if script.Parent.InputBox.Text == Codes[3] then
RemoteEvent:FireServer(200, Codes[3])
end
end
end)
There’s a couple of issues:
- Your code is vulnerable to exploits
- Your code isn’t scalable (it’s written in a way that updating it will be an eventual issue)
The client should not tell the server how much cash to give to the player; that needs to be done on the server:
script.Parent.EnterButton.MouseButton1Click:Connect(function()
RemoteEvent:FireServer(script.Parent.InputBox.Text)
end)
This only tells the server what the user typed in the Textbox. This is better because even if an exploiter changes what’s being sent through the remote, the server will still check if whatever was sent is correct.
local codes = {
["SomeOffTtber"] = 100,
["HoonIsCat"] = 100,
["RELEASE!"] = 200
}
RemoteEvent.OnServerEvent:Connect(function(player, code)
local amount = codes[code]
if amount then
--...
player.leaderstats.Cash.Value += amount
end
end)
This detects when the event is fired on the server checks to see if the code is in table. If it is, it adds the cash amount to the player’s leaderstats.
Where --...
is written, that would be your method of checking if the player already redeemed the code. If you want to save whether or not the code was already redeemed, you can utilize DataStores:
So in between the if amount then I put the numbers there or resay the codes then numbers
No, the if amount then
checks if the amount
variable isn’t nil
. For example, if someone types something that isn’t in the table, the amount
variable would be nil
. But if the code is in the table, the amount
variable would be whatever the value in the table is.
local _table = { ["code"] = 20 }
local value = _table.code
local value2 = _table.secondCode
print(value) --> 20
print(value2) --> nil
yes
Soo, to check if that’s an Available code if so give the money sorry for this I’m new to the scripting and too also remember if its been saved through the datstore
1 Like