Issue with code redeeming

This is extremely exploitable as people could add any code they wanted to the table and assign it a ridiculous amount of money upon redeeming it.

Ye it didn’t work i put it in the ui 1

here we go

I don’t really know what to tell you right now because your conditional and logical statements are very messy and it’s really hard for me to fix that for you right now since I don’t have access to studio or a computer. When I get home I will try and help you if your problem hasn’t been solved.

In the meantime, look at the article I linked in one of my previous replies on Conditional Construction and hopefully you’ll find some help there.

alr sorry and thanks and I saw the article I will leave the code how you just saw in the last screenshot

1 Like

It’s looking better but now align all the elseif statements under the regular if statement so it’s a straight and vertical line.

I am so sorry I used a YouTube video for it I’m not a good coder

1 Like

Let’s go ahead and move this to DMs since it’s getting way too long now and we’re basically spamming the scripting support category.

Alright cya their thanks for trying to help me

--SERVER
local RS = game:GetService("ReplicatedStorage")
local RemoteEvent = RS:WaitForChild("CodeEvent")

RemoteEvent.OnServerEvent:Connect(function(Player, Reward, Code)
	if not Player:FindFirstChild(Code) then
		local Redeemed = Instance.new("BoolValue")
		Redeemed.Parent = Player
		Redeemed.Name = Code
		Redeemed.Value = false
		if not Redeemed.Value then
			Player.leaderstats.Money.Value += Reward
			Redeemed.Value = true
		end
	end
end)
--LOCAL
local codes = {"RELEASE!", "REALISIM TIME", "Dog", "Cat", "Subscribe"}
local RS = game:GetService("ReplicatedStorage")
local RemoteEvent = RS:WaitForChild("CodeEvent")
local Frame = script.Parent
local Button = Frame:WaitForChild("EnterButton")
local Box = Frame:WaitForChild("InputBox")

Button.MouseButton1Click:Connect(function()
	if Box.Text == codes[1] then
		RemoteEvent:FireServer(50, codes[1])
	elseif Box.Text == codes[2] then
		RemoteEvent:FireServer(100, codes[2])
	elseif Box.Text == codes[3] then
		RemoteEvent:FireServer(200, codes[3])
	elseif Box.Text == codes[4] then
		RemoteEvent:FireServer(160, codes[4])
	elseif Box.Text == codes[5] then
		RemoteEvent:FireServer(400, codes[5])
	end
end)

Alternatively the local script (UI part) could become.

local codes = {["RELEASE!"] = 50, ["REALISIM TIME"] = 100, ["Dog"] = 200, ["Cat"] = 160, ["Subscribe"] = 400}
local RS = game:GetService("ReplicatedStorage")
local RemoteEvent = RS:WaitForChild("CodeEvent")
local Frame = script.Parent
local Button = Frame:WaitForChild("EnterButton")
local Box = Frame:WaitForChild("InputBox")
local ParentBox = script:WaitForChild("ParentBox")

Button.MouseButton1Click:Connect(function()
	for code, reward in pairs(codes) do
		if Box.Text == code then
			RemoteEvent:FireServer(reward, code)
		end
	end
end)

This may not be related with your issue, but by allowing the client to pass the reward as an arguement you are giving exploiters infinite amount of cash. What you should do instead is only pass the code and check on the server like this:

UI:

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local RemoteEvent = ReplicatedStorage:WaitForChild("CodeEvent")
script.Parent.EnterButton.Activated:Connect(function()
	RemoteEvent:FireServer(script.Parent.InputBox.Text)
end)

Server:

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local RemoteEvent = ReplicatedStorage:WaitForChild("CodeEvent")

--PLEASE STORE THIS IN THE SERVER
--else exploiters can get infinite cash
local codes = {
	["RELEASE!"] = 50,
	["REALISIM TIME"] = 100,
	["Dog"] = 200,
	["Cat"] = 160,
	["Subscribe"] = 400
}

RemoteEvent.OnServerEvent:Connect(function(Player, Code) --only pass the code
	local found = Player:FindFirstChild(Code) 
	if not found or not found.Value then
		local Reward = codes[Code] --get the actual reward
		if not Reward then return end 
		--only continue the script execution if a reward exists, and they don't have it
		local Redeemed = Instance.new("BoolValue")
		Redeemed.Name = Code
		Player.leaderstats.Money.Value += Reward
		--Parent the value AFTER you give them coins 
		--it an error occurs on the line above it wont redeem the code
		Redeemed.Value = true
		Redeemed.Parent = Player 
	end
end)
1 Like

i put 1 in the ui (not in a button) and i put the other in server script service is this correct

Having 2 versions of the same table client-side and server-side can have some benefits like avoiding remote spam from normal users, although under all circumstances you should make sure the client can’t sent random values to the server as rewards.

Edit: I may have misunderstood your reply, if you meant the code snippets, they should replace the scripts you labeled as ā€œUIā€ and ā€œServerā€ accordingly.

table.find() returns the following table, however, you need to declare the part of it you want. The table should look like this:

Codes = {
    "RELEASE" = 50
}

Then, the index variable should look like this:

local index = table.find(Codes[1], script.Parent.InputBoxText)
RemoteEvent:FireServer(index, table.find(Codes[2]))

It should look something like that!

sorry for late response I will try this in a blank baseplate game