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

Why is this goin down to 'else' and skips 'if'? (FIXED IT)

script.Parent.MouseButton1Down:connect(function()
	if game:GetService("GamePassService"):PlayerHasPass(game.Players.LocalPlayer, 167686361)
	script.Parent.Parent.Frame.Visible = true
		else
		script.Parent.Parent.NoPass.Visible = true
		wait(5)
		script.Parent.Parent.NoPass.Visible = true
	end
end)

Even though I have the gamepass, it skips down to the 'else'.

2 answers

Got it working:

local player = script.Parent.Parent.Parent.Parent
local noPass = script.Parent.Parent.NoPass
local gui = script.Parent.Parent.Frame

script.Parent.MouseButton1Down:connect(function()
	if game:GetService("GamePassService"):PlayerHasPass(player, 167686361) then
	gui.Visible = true
		else
		noPass.Visible = true
		wait(5)
		noPass.Visible = false
	end
end)
script.Parent.MouseButton1Down:connect(function()
    if game:GetService("GamePassService"):PlayerHasPass(game.Players.LocalPlayer, 167686361) then -- You forgot to add "then"
    script.Parent.Parent.Frame.Visible = true
        else
        script.Parent.Parent.NoPass.Visible = true
        wait(5)
        script.Parent.Parent.NoPass.Visible = true
    end
end)

You forgot the "then" after the if condition. If you come across another issue, then we may need to take a harder look. This is just what I noticed at first glance.

5 comments

0

I've added that in-game, I must of copied it wrong. But that still isn't working like it should.

0

The output in a normal server (in-game): Game passes can only be queried by a Script running on a ROBLOX game server

1

Is it in a local script or a server script?

0

If it is a local script, that would explain why it works when you play through the studio, but not through the server.

0

It's a local script, and I'm testing this in a normal game, by joining the place through the PLAY button.

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