Help of a script that if you have a game pass spawns in a different location

Hello, I need help fixing a script of mine.


local Players = game:GetService('Players')
local MarketPlaceService = game:GetService('MaketPlaceService')
local TeleportService = game:GetService("TeleportService")

local GamepassId = 678174726 --gamepass id goes here


Players.PlayerAdded:Connect(function(Player)
	if MarketPlaceService:UserOwnsGamePassAsync(Player.UserId, GamepassId) then
		TeleportService:Teleport(game.Workspace["Custom spawn"].Spawn, Player)
	end
end)

That is the script.

So basically, I need to spawn you in a different spawn point if you own a game pass.

  • There’s a folder called “Custom spawn”
  • There is a part in there call “Sqawn”
2 Likes

Ello! You don’t use teleport service because it’s mainly use is to teleport to different games and places. You could move it with the players character, you’ll need its character and use MoveTo()

1 Like

The Teleport function of the TeleportService is used to teleport players between places or games, not to move the player character around the map within a single place.

If you want an easy way to make what you’re describing, you can make a different team for the players owning the game pass, if they own it add them to said team by script. Then set the Spawn.TeamColor property to the team.TeamColor property of said team and all players who own the game pass should be teleported there automatically(ensure to do all this in a server script).

1 Like

What type of script would I use and where would I put it?

1 Like

In your playeradded script, that’s where you would put it, and script it.

1 Like

No the script.
(Cap: ABCDEFGHIJLOPQRSTUVWXYZ)

1 Like

Yeah, you’ll have to code it in your player added script or your script that contains the gamepass.

This should work:

local Players = game:GetService('Players')
local MarketPlaceService = game:GetService('MaketPlaceService')
local TeleportService = game:GetService("TeleportService")

local GamepassId = 678174726 --gamepass id goes here


Players.PlayerAdded:Connect(function(Player)
	if MarketPlaceService:UserOwnsGamePassAsync(Player.UserId, GamepassId) then
        local char = Player.Character or Player.CharacterAdded:Wait()
        local root = char:FindFirstChild("HumanoidRootPart")
        if not root then return end
        local customSpawn = game.Workspace["Custom spawn"].Spawn
        root.CFrame = customSpawn.CFrame
	end
end)

Edit: Remember that this only spawns the player once to this location.

Following script would spawn the player there everytime:

local Players = game:GetService('Players')
local MarketPlaceService = game:GetService('MaketPlaceService')
local TeleportService = game:GetService("TeleportService")

local GamepassId = 678174726 --gamepass id goes here


Players.PlayerAdded:Connect(function(Player)
	if MarketPlaceService:UserOwnsGamePassAsync(Player.UserId, GamepassId) then
        Player.CharacterAdded:Connect(function()
            local char = Player.Character or Player.CharacterAdded:Wait()
            local root = char:FindFirstChild("HumanoidRootPart")
            if not root then return end
            local customSpawn = game.Workspace["Custom spawn"].Spawn
            root.CFrame = customSpawn.CFrame
        end)
	end
end)

Hello!

As @NyrionDev said, TeleportService teleports the player to a place or a different experience. So if you want to move the player to a spawn what you have to do is to change the HumanoidRootPart’s CFrame to the spawn’s CFrame.

This is an example (I didn’t test it):

local Players = game:GetService('Players')
local MarketPlaceService = game:GetService('MarketplaceService')
local Spawn = game.Workspace["Custom spawn"].Spawn

local GamepassId = 678174726 --gamepass id goes here


Players.PlayerAdded:Connect(function(Player)
	if MarketPlaceService:UserOwnsGamePassAsync(Player.UserId, GamepassId) then 
 
  Player.CharacterAdded:Connect(function(character)
            local HRP = character:WaitForChild("HumanoidRootPart")
            task.wait()
            HRP.CFrame = Spawn.CFrame
        end)
	end
end)

(Sorry if the code doesn’t look “natural” :smile: It’s because I wrote it on my phone! But it doesn’t affect the code)

uhh, first of all, why do you respond to me? and second, why did you post this when I already posted the same solution?

I’m kinda new on the DevForum so I’m not really good at using the DevForum tools and all of that. And about the script, sorry I was sleepy yesterday I didn’t see the characterAdded in your script, my bad.

Hello @ShermaanCat ! Your code worked but your code had a typo.

You put:

local MarketPlaceService = game:GetService('MaketPlaceService')

When it is:

local MarketPlaceService = game:GetService('MarketplaceService')

So here is the updated code:

local Players = game:GetService('Players')
local MarketPlaceService = game:GetService('MarketplaceService')
local Spawn = game.Workspace["Custom spawn"].Spawn

local GamepassId = 678174726 --gamepass id goes here
 


Players.PlayerAdded:Connect(function(Player)
	if MarketPlaceService:UserOwnsGamePassAsync(Player.UserId, GamepassId) then 

		Player.CharacterAdded:Connect(function(character)
			local HRP = character:WaitForChild("HumanoidRootPart")
			task.wait()
			HRP.CFrame = Spawn.CFrame
		end)
	end
end)

Once again, thank you @ShermaanCat

PS, sorry @kwkxbxkdkdjjd I did not understand your code.

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.