Touch part script does not work

Now slowly build back up the code. Use this:

local TS = game:GetService("TeleportService")
local Players = game:GetService("Players")
--local code = TS:ReserveServer(86819814841501)
local players = Players:GetPlayers()
--local badgeID = 155440073325875
local part = script.Parent

local debounce = true

part.Touched:Connect(function(hitpart)
	local humanoid = hitpart.Parent:FindFirstChild("Humanoid")
	if humanoid and debounce then
		debounce = false
		for i, player in pairs(game.Players:GetPlayers()) do
			
			print("do stuff", humanoid)
			
		end
	end
end)

test it out first, then replace “do stuff”

That is what im doing rn but the intro takes 25 seconds each play

It works from this now


local debounce = true


script.Parent.Touched:Connect(function(hitpart)
	print("TEST")
	local humanoid = hitpart.Parent:FindFirstChild("Humanoid")
	if humanoid then
		debounce = false
		for i, player in pairs(game.Players:GetPlayers()) do
			player.PlayerGui.LoadingScreen.Frame.Visible = true
			game:GetService("BadgeService"):AwardBadge(player.UserId, badgeID)
			wait(4)
			TS:TeleportToPrivateServer(86819814841501, code, players)
		end
	end
end)

now put the test print inside the for loop. and don’t forget the if humanoid and debounce then :sweat_smile:

Not quite. It does not print when I do all the locals so im removing one by one

comment out the local code = ...
it might be waiting for the server

So it is that one. But how do I make it so it actually works?

Well does it print test in the for loop? And don’t forget the debonce in the if statement, otherwise it’s redundant :sweat_smile:

I’ve never worked with TeleportService so I don’t know. I think that’d be a question for another person :D

The gui shows so thats the proof it works

it is yielding on waiting for “ForceField” so you should remove that or fix it.
If anything else yields or errors, fix or remove that.

Teleports don’t work in studio, you’ll have to play the actual game to see if the teleport works or not.

No it does not wait for ForceField that is a different script which works

Ok I tested it in game and the gui works its just not teleporting to the game now

That’s because when you call the ReserveServer method it will yield(wait) for the server. if it was a game tested in an actual roblox player it would work, but teleportservice does not work in the studio.

Here is the error

I have noticed that it just does not teleport me into the private server

It’s been a while and I am still waiting to solve this teleport problem

Try this? You must play in the actual game client to be teleported.

local TS = game:GetService("TeleportService")
local Players = game:GetService("Players")
local BadgeService = game:GetService("BadgeService")
local code = TS:ReserveServer(86819814841501)
local badgeID = 155440073325875
local part = script.Parent

local debounce = true

part.Touched:Connect(function(hitpart)
	local humanoid = hitpart.Parent:FindFirstChild("Humanoid")
	local player = Players:GetPlayerFromCharacter(hitpart.Parent)
	
	if humanoid and player and debounce then
		debounce = false
		local players = Players:GetPlayers()
		
		-- loading screen? I copied this path from the original script soo you may want to confirm it lol.
		for _, plr in ipairs(players) do
			if plr.PlayerGui and plr.PlayerGui:FindFirstChild("LoadingScreen") then
				plr.PlayerGui.LoadingScreen.Frame.Visible = true
			end
		end
		
		-- give badge
		for _, plr in ipairs(players) do
			pcall(function()
				if not BadgeService:UserHasBadgeAsync(plr.UserId, badgeID) then
					BadgeService:AwardBadge(plr.UserId, badgeID)
				end
			end)
		end
		
		task.wait(4)
		
		-- teleport and retry if fail
		local success = false
		local attempts = 0
		local maxAttempts = 3
		
		while not success and attempts < maxAttempts do
			success = pcall(function()
				TS:TeleportToPrivateServer(86819814841501, code, players)
			end)
			
			if not success then
				attempts += 1
				task.wait(1)
			end
		end
		
		-- debounce reset
		if not success then
			for _, plr in ipairs(players) do
				if plr.PlayerGui and plr.PlayerGui:FindFirstChild("LoadingScreen") then
					plr.PlayerGui.LoadingScreen.Frame.Visible = false
				end
			end
			debounce = true
		end
	end
end)```

The reason might be is because you are in a test server on roblox studio, meanwhile it should work in the published experience

Thats what I was doing but after hours I finally fixed it

1 Like