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)
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)