Issue with code redeeming

I have a code event in replicated storage and I have 2 scripts 1 in server scrive service and another in the Gui

Server script service code:

local RemoteEvent = game.ReplicatedStorage.CodeEvent

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.Money.Value += Reward
		Redeemed.Value = true
	end
end

end)

  1. Ui Code

local codes = {“RELEASE!”,“REALISIM TIME”,“Dog”,“Cat”,“Subscribe”}
local RemoteEvent = game.ReplicatedStorage.CodeEvent

script.Parent.EnterButton.MouseButton1Click:Connect(function()
if script.Parent.InputBox.Text == codes[1] then
RemoteEvent:FireServer(50, 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])
else
if script.ParentBox.Text == codes[4] then
RemoteEvent:FireServer(160, codes[4])
else
if script.ParentBox.Text == codes[5] then
RemoteEvent:FireServer(400, codes[5])
end
end
end
end
end
end)

here is what it looks like in the actual ui

Code

2 Likes

Incase that was to confusing here it is in a screen shot

Code 1. Gui Code Code:

Code 2. Serverscriptservice Code:

so when I go to redeem a code it doesn’t give me money

Going off your screenshot (which is much more helpful, thank you for that), I would use ifelse statements instead of using else statements then putting an if statement inside it.

Edit: You also labeled your code wrong in the screenshot reply. Your ServerScriptService code is labeled as the GUI code, and vice versa.

where abouts would i put the if else and else statments (i am sorry im not good on coding)

Just combine the else with the nested (the statement inside the else) if statement. For example

elseif script.Parent.InputBox.Text == codes[2] then
RemoteEvent:FireServer(100, codes[2])

Sorry for the bad formatting. I’m on my phone at the moment.

You will probably have to delete some of your ends for it to function.

Edit: Your script for codes[4] and codes[5] are messed up. ParentBox is not a thing and I’m suspecting you meant to type .Parent.InputBox

1 Like

Ok so addon the if’s to elseif and what do i do with the normal if’s

Delete the normal ifs and put everything in the normal if inside the new elseif statement.

Send a screenshot of your code after you’ve made the changes.

like that also the top elseif has a red underline on it

Yes sorry keep the top elseif as a regular if statement. Also you are going to have to delete some of the ends.

How is this:

You need to have an end with a parentheses after it to close the MouseClickEvent. Also I’m pretty sure you should only have one regular end.

I suggest looking up ifelse statements on the DevHub because your code is still really messed up and I can’t make it for you right now because I don’t have access to my desktop. I will try to help you the best I can but I don’t know how to explain to you how to format the statements.

Like this then?

because if so when I put end) it underlines the end) in red but when I put end its fine

You need one end with a parentheses and one without I believe. If there is still a red line under the end, add in more.
Try looking at this.

this seems to be fine and their isnt any red underline of the code

Put script.Parent.InputBox.Text == codes[2] then on the same line as the ifelse statement directly above it. Do that for the rest of them as well.

Also backspace so that all the elseifs are in a straight vertical line.

Instead of doing this, you can make something like this.

Codes = {
	RELEASE = {
		Money = 50
	}
}
local RemoteEvent = game.ReplicatedStorage.CodeEvent
script.Parent.EnterButton.MouseButton1Click:Connect(function()
	if table.find(Codes,script.Parent.InputBox.Text) then
		local index = table.find(Codes,script.Parent.InputBox.Text)
		RemoteEvent:FireServer(index.Money,index)
	end
end)

try something along these lines, i’m not sure if table.find is the right function but if it doesnt work update me

why would i need a script.Parent.InputBox.Text == codes[2] then when i have it and if i need it where do i put it exactly

I was referring to the one you already had in your code. Just move that up on the same line as the elseif statement above it.