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

[URGENT] If Player Has Gamepass Teleport on Touch?

I have a script where when you touch a part (its actually a union) and if you have a gamepass, then it is supposed to teleport you to said place, and if you dont own the gamepass, it prompts the purchase of the gamepass. But it doesnt work for no reason, i would really appreciate if you would look into this!

local player = game.Players.LocalPlayer
local id = 7549285
local teleport = game.Workspace.VIPAREA

script.Parent.Touched:Connect(function(part)
	if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player, id) then
		local humanoid = part.Parent:FindFirstChild("Humanoid")
		if (humanoid ~= nil) then
			humanoid.Parent.Head.CFrame = CFrame.new(teleport.CFrame) 
		end
	else
		game:GetService("MarketplaceService"):PromptGamePassPurchase(player, id)
	end
end)

9 comments

1

teleport their humanoid root part instead of their head

0

it says the error is in line 6? Idk what you mean, could you show me an example

1

What does the error say

0

Argument 1, Missing or Nil

1

Is this a server script or a local script?

0

server script

0

do player.userId instead of player on line 6

0

Ill try that

0

still doesnt work

2 answers

✓ Accepted answer

You're not supposed to use game.Players.LocalPlayer in a server script. Thats only for local scripts.

And I'm not too sure about this but I think you gotta change (player,id) on line 6 to (player.UserId,id)

Hope this helped!

local id = 7549285
local teleport = game.Workspace.VIPAREA

script.Parent.Touched:Connect(function(part)
	if part.Parent:FindFirstChild("Humanoid") then
		local player = game.Players[part.Parent.Name]
		if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId, id) then
        		local humanoid = part.Parent:FindFirstChild("Humanoid")
			if (humanoid ~= nil) then
				humanoid.Parent.Head.CFrame = CFrame.new(teleport.CFrame) 
			end 
		else
			game:GetService("MarketplaceService"):PromptGamePassPurchase(player, id)
		end
	end
end)

1 comment

0

I’ll try this and see if it works

UserOwnsGamePassAsync( player.UserId, id) You used player instead of player.UserId

1 comment

0

on line 6

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