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

Why isn't the correct if statement functioning if they own/have something?

I'm currently revamping the xp system for a game that I'm working on and I have a bit of an issue. If a player has both a game pass and badge, they should get x5 their xp, but that doesn't seem to work. It will usually just set their xp to x3 which is from the gamepass. The same goes for when it's a double xp day, instead of doing x7 for owning both, it will only do the x2 as if they don't have the gamepass or badge. I'd like to know what is causing this to happen and how can it be fixed. I'd also like to know how I can make the print statements only function once so that it doesn't spam the console when someone receives xp.

--	// FileName: PlayerXP.lua
--	// Written by: Alpha Toon
--  // Date Created: 8/1/2017
--	// Description: Module that sets xp based on a players level and other elements.

local PlayerXP = {}
local date = require(game.ReplicatedStorage.Date)
local day = date()
local mark = game:GetService("MarketplaceService")
local gp = false
local badge = false
local assignXP = 0
local newXP = 0

function PlayerXP.giveExperience(player)
    local level = tonumber(game.ReplicatedStorage:FindFirstChild(player.Name .. "Level").Value)

    if mark:PlayerOwnsAsset(player, 581880857) then
        print("User has x3 Experience Game Pass")
    	gp = true
    end

    if mark:PlayerOwnsAsset(player, 918350650) then
        print("User has birthday badge")
    	badge = true
    end

    if level < 100 then
        assignXP = level * 5.5
        newXP = assignXP
    elseif level >= 100 and level < 150 then
        assignXP = level * 5.2
        newXP = assignXP
    elseif level >= 150 and level < 200 then
        assignXP = level * 4.7
        newXP = assignXP
    elseif level >= 200 and level < 250 then
        assignXP = level * 4.5
        newXP = assignXP
    elseif level >= 250 and level < 300 then
        assignXP = level * 4.3
        newXP = assignXP
    elseif level >= 300 and level < 350 then
        assignXP = level * 4
        newXP = assignXP
    elseif level >= 350 and level < 400 then
        assignXP = level * 3.9
        newXP = assignXP
    elseif level >= 450 and level < 500 then
        assignXP = level * 3.7
        newXP = assignXP
    elseif level >= 500 and level < 550 then
        assignXP = level * 3.4
        newXP = assignXP
    elseif level >= 550 and level < 600 then
        assignXP = level * 2.9
        newXP = assignXP
    elseif level >= 650 and level < 700 then
        assignXP = level * 2.7
        newXP = assignXP
    elseif level >= 700 and level < 750 then
        assignXP = level * 2.4
        newXP = assignXP
    elseif level >= 750 and level < 800 then
        assignXP = level * 2.2
        newXP = assignXP
    elseif level >= 850 and level < 900 then
        assignXP = level * 1.5
        newXP = assignXP
    elseif level >= 900 and level < 999 then
        assignXP = level * 1.3
        newXP = assignXP
    elseif level >= 999 then
        assignXP = level * 0.7
        newXP = assignXP
    end

    if day.weekday == 1 or day.weekday == 7 then
        print("Double XP Weekend is active")

        if gp == false and badge == false then
            newXP = assignXP * 2
            player.leaderstats1.XP.Value = player.leaderstats1.XP.Value + newXP
			print("x2 XP")
        elseif gp == true and badge == false then
            newXP = assignXP * 5
            player.leaderstats1.XP.Value = player.leaderstats1.XP.Value + newXP
			print("x5 XP")
        elseif gp == false and badge == true then
            newXP = assignXP * 4
            player.leaderstats1.XP.Value = player.leaderstats1.XP.Value + newXP
			print("x4 XP")
        elseif gp == true and badge == true then
            newXP = assignXP * 7
            player.leaderstats1.XP.Value = player.leaderstats1.XP.Value + newXP
			print("x7 XP")
        end
    elseif day.weekday ~= 7 or day.weekday ~= 1 and gp == true and badge == false then
        newXP = assignXP * 3
        player.leaderstats1.XP.Value = player.leaderstats1.XP.Value + newXP
		print("x3 XP")
    elseif day.weekday ~= 7 or day.weekday ~= 1 and gp == false and badge == true then
        newXP = assignXP * 2
        player.leaderstats1.XP.Value = player.leaderstats1.XP.Value + newXP
		print("x2 XP")
    elseif day.weekday ~= 7 or day.weekday ~= 1 and gp == true and badge == true then
        newXP = assignXP * 5
        player.leaderstats1.XP.Value = player.leaderstats1.XP.Value + newXP
		print("x5 XP")
    else
        player.leaderstats1.XP.Value = player.leaderstats1.XP.Value + newXP
    end
end
return setmetatable(PlayerXP, {__index = table})

1 answer

✓ Accepted answer

Hi, I figured out the answer

  elseif day.weekday ~= 7 or day.weekday ~= 1 and gp == true and badge == false then
        newXP = assignXP * 3
        player.leaderstats1.XP.Value = player.leaderstats1.XP.Value + newXP
        print("x3 XP")
    elseif day.weekday ~= 7 or day.weekday ~= 1 and gp == false and badge == true then
        newXP = assignXP * 2
        player.leaderstats1.XP.Value = player.leaderstats1.XP.Value + newXP
        print("x2 XP")
    elseif day.weekday ~= 7 or day.weekday ~= 1 and gp == true and badge == true then
        newXP = assignXP * 5
        player.leaderstats1.XP.Value = player.leaderstats1.XP.Value + newXP
        print("x5 XP")

Thats your script ^

I edited it and instead of "Or" i changed it to "And"

  elseif day.weekday ~= 7 and day.weekday ~= 1 and gp == true and badge == false then
        newXP = assignXP * 3
        player.leaderstats1.XP.Value = player.leaderstats1.XP.Value + newXP
        print("x3 XP")
    elseif day.weekday ~= 7 and day.weekday ~= 1 and gp == false and badge == true then
        newXP = assignXP * 2
        player.leaderstats1.XP.Value = player.leaderstats1.XP.Value + newXP
        print("x2 XP")
    elseif day.weekday ~= 7 and day.weekday ~= 1 and gp == true and badge == true then
        newXP = assignXP * 5
        player.leaderstats1.XP.Value = player.leaderstats1.XP.Value + newXP
        print("x5 XP")

Because or would just say if weekday is ~= 7 or something else, the weekday wouldn't be counted so I used and so if it is a weekday this will work

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