Touch part script does not work

I am trying to make a script where when you touch a part it will make a gui visible then gives all the players in the server a badge and teleports to a new private server. And yes I have canTouch on. If you could solve this problem I will be very greatful!

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 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)
1 Like

Change your code to:

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)

  print("touchedWorked")

	--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)

to even see if it works.
Also don’t forget to change your if to if humanoid and debounce then :D

I tried that and it did not print the message

does CanCollide affect .Touched? if so, is that the reason

I said that in the message I have it on

That means that the Touched event doesn’t fire. Check if canCollide and canQuery (I think it might affect it) are off.

Screenshot 2024-12-14 215356

turn cancollide on and test
character

hmmm
that might be it
do you absolutely need it to be turned off?

I tried that an hour ago and still didnt work

I did both on and off and didnt work either way

is it a local script? If so, it won’t work. You’d need a server script (just called Script)

proof:
image
image
image

Screenshot 2024-12-14 215740

That is so strange…

It literally works for me?


image

Not even this code will work?

Is it maybe because I do the play here instead of play? It’s probably not but I do get an infinite yield from a different script from doing that

It still works for me if I do “play here”. Do you have anything else before the touched event in the script?

I do not have anything else before it

Wait I am getting some outputs

But I had to simplify it down to this



script.Parent.Touched:Connect(function(hitpart)
	print("test")
		
	
end)