Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
0msh 333 Moderation Voter
4 years ago

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)
0
I don't understand what your trying to make here of this script? voidofdeathfire 148 — 4y
0
Can you add what the local script says? voidofdeathfire 148 — 4y

1 answer

Log in to vote
1
Answered by 4 years ago

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)
0
The else statement is probably why its not working. voidofdeathfire 148 — 4y
Ad

Answer this question