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

my code redemption system can only redeem one code, help?

so it only works with "code1" but not "code2", and idk what's wrong

game.ReplicatedStorage.cd.OnServerEvent:Connect(function(player,code)
	local ss = game:GetService("ServerStorage")
	local reward = ss:FindFirstChild("PlayerMoney")
	local r = reward:FindFirstChild(player.Name)
	local key = "codes-"..player.userId
    if code == "code1"  then
	if player.Codes:FindFirstChild(code) == nil then
	local bool = Instance.new("BoolValue")
	bool.Parent = player:FindFirstChild("Codes")
	bool.Name = code
	r.Value = r.Value + 500
	elseif code == "code2"  then
	if player.Codes:FindFirstChild(code) == nil then
	local bool = Instance.new("BoolValue")
	bool.Parent = player:FindFirstChild("Codes")
	bool.Name = code
	r.Value = r.Value + 500
	end
	end
end
end)

2 comments

0

I don't understand what your trying to make here of this script?

0

Can you add what the local script says?

1 answer

✓ Accepted answer

In short, Why put it else statement when the code isnt directly relating to the subject.

Remove the else statement and change the script like this:

game.ReplicatedStorage.cd.OnServerEvent:Connect(function(player,code)
    local ss = game:GetService("ServerStorage")
    local reward = ss:FindFirstChild("PlayerMoney")
    local r = reward:FindFirstChild(player.Name)
    local key = "codes-"..player.userId
    if code == "code1"  then
    if player.Codes:FindFirstChild(code) == nil then
    local bool = Instance.new("BoolValue")
    bool.Parent = player:FindFirstChild("Codes")
    bool.Name = code
    r.Value = r.Value + 500
end
end
    if code == "code2"  then
    if player.Codes:FindFirstChild(code) == nil then
    local bool = Instance.new("BoolValue")
    bool.Parent = player:FindFirstChild("Codes")
    bool.Name = code
    r.Value = r.Value + 500
    end
    end
end)

1 comment

0

The else statement is probably why its not working.

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