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

My final 'elseif' statement isn't running for users who don't own the gamepasses?

I have two gamepasses : x2 points and x3 points. When you touch the end part of each minigame, you receive points and the number of points are influenced by the gamepass you own. The gamepasses work fine, but I found out that players without the gamepass are not receiving any points. I looked into the final elseif statement and it turns out it's not running at all for non-gamepass owners. Anyone know why?

local winnames = game.Workspace:WaitForChild("WinNames")
local db = false
script.Parent.TouchEnded:connect(function(hit)
	if hit.Parent ~= nil then
		if hit.Parent ~= nil and db==false then
			db=true
			if hit.Parent.Humanoid.Health ~= 0 then
				local player = game.Players:GetPlayerFromCharacter(hit.Parent)
				player.Settings.Winner.Value = true
				local spawns = game.Workspace.Lobby.Spawns:GetChildren()
				hit.Parent.HumanoidRootPart.CFrame = spawns[math.random(1,#spawns)].CFrame + Vector3.new (0,3,0)
				game.Workspace.NumWinners.Value=game.Workspace:WaitForChild("NumWinners").Value+1
				local ownsGamepass = game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId, 8896759)
				local ownsx3Gamepass = game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId, 8918156)
				player.Settings.Winner.Value=false
				if ownsx3Gamepass==true then
					player.leaderstats.Wins.Value = player.leaderstats.Wins.Value+1
					player.leaderstats.Points.Value = player.leaderstats.Points.Value+30
					player.earned.Value = player.earned.Value + 30
				if ownsGamepass==true then
					player.leaderstats.Wins.Value=player.leaderstats.Wins.Value+1
					player.leaderstats.Points.Value=player.leaderstats.Points.Value+20
					player.earned.Value = player.earned.Value + 20
				elseif ownsGamepass==false and ownsx3Gamepass==false then
					print("oh no")
					player.leaderstats.Wins.Value=player.leaderstats.Wins.Value+1
					player.leaderstats.Points.Value=player.leaderstats.Points.Value + 10
					player.earned.Value = player.earned.Value + 10
				end
			end
			wait(2)
			player.earned.Value = 0
			db=false
		end
	end
end
end)

1 answer

The reason it's erroring is because elseif is used to create another thing in your code like a new thread.Parent Also you do not need an else if if your not making another thread instead use an else.

The else if is basically like saying or.

local winnames = game.Workspace:WaitForChild("WinNames")
local db = false
script.Parent.TouchEnded:connect(function(hit)
    if hit.Parent ~= nil then
        if hit.Parent ~= nil and db==false then
            db=true
            if hit.Parent.Humanoid.Health ~= 0 then
                local player = game.Players:GetPlayerFromCharacter(hit.Parent)
                player.Settings.Winner.Value = true
                local spawns = game.Workspace.Lobby.Spawns:GetChildren()
                hit.Parent.HumanoidRootPart.CFrame = spawns[math.random(1,#spawns)].CFrame + Vector3.new (0,3,0)
                game.Workspace.NumWinners.Value=game.Workspace:WaitForChild("NumWinners").Value+1
                local ownsGamepass = game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId, 8896759)
                local ownsx3Gamepass = game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId, 8918156)
                player.Settings.Winner.Value=false
                if ownsx3Gamepass==true then
                    player.leaderstats.Wins.Value = player.leaderstats.Wins.Value+1
                    player.leaderstats.Points.Value = player.leaderstats.Points.Value+30
                    player.earned.Value = player.earned.Value + 30
                if ownsGamepass==true then
                    player.leaderstats.Wins.Value=player.leaderstats.Wins.Value+1
                    player.leaderstats.Points.Value=player.leaderstats.Points.Value+20
                    player.earned.Value = player.earned.Value + 20
                else 
                    print("oh no")
                    player.leaderstats.Wins.Value=player.leaderstats.Wins.Value+1
                    player.leaderstats.Points.Value=player.leaderstats.Points.Value + 10
                    player.earned.Value = player.earned.Value + 10
                end
            end
            wait(2)
            player.earned.Value = 0
            db=false
        end
    end
end
end)

1 comment

0

still not working :/ 'oh no' is not being printed (the account im using to test with does not own the gamepass)

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