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

Simple PlayerHasPass code - why doesn't it work?

function Click()
	local id = 227017712
 
	game.Players.PlayerAdded:connect(function(player)
    	if game:GetService("GamePassService"):PlayerHasPass(player, id) then 
		print'has pass'
		script.Parent.Parent.Parent.Parent.Character.Torso.CFrame = CFrame.new(-463.884, -15.558, 140.897)
	else
		script.LocalPlayer.StarterGui.NoPass.NoPass.Visible = true
		print'has no pass'
		wait(5)
		script.LocalPlayer.StarterGui.NoPass.NoPass.Visible = false
		end
	end)
end

script.Parent.MouseButton1Down:connect(Click)

no output,

1 answer

--EDIT[2]--

Remove the PlayerAdded event - This is making it so whenever any player joins then their position gets set to the specified location.

This should be a regular script, define plr.

local id = 227017712
local plr --Define!

function Click()
	if game:GetService("GamePassService"):PlayerHasPass(player, id) then
		plr.Character.Torso.CFrame = CFrame.new(-463.884, -15.558, 140.897)
	else
		plr.PlayerGui.NoPass.NoPass.Visible = true
		wait(5)
		plr.PlayerGui.NoPass.NoPass.Visible = false
	end
end

script.Parent.MouseButton1Down:connect(Click)

4 comments

0

This script moves the player to the position without even clicking the GUI button, that is not what I want it to do, I want the player to chose whenever he wants to teleport to the position during the game.

0

Edited

1

PlayerHasPass can't be used from a LocalScript.

0

Edited[2]

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