My script randomly stops working?

Well not entirely random, but it works sometimes, then not the other. It only happens when the game is public, so idk if it’s multiple users trying the script or something else.
Anyway, the script is like a keycard script, except when a player touches the part with an item, it will tp them to a certain place.


teleportA = script.Parent.TeleportA
teleportB = script.Parent.TeleportB

teleportA.Touched:connect(function(hit)
	if canteleport == true and hit.Parent.Name == "RedGear" then
		canteleport = false
		wait(0.2)
		hit.Parent.Parent.HumanoidRootPart.CFrame = teleportB.CFrame
		wait(1)
		canteleport = true
	end
end)```
 
Is there something I should be optimizing/changing? Would like feedback.
1 Like

So is there a script intefering with teleport A or B?

Uhhh, no. No intertwining scripts with that tp. Only issue I can think of is either a gamepass messing w/ it or more than one person using it at once. Some servers have the issue, and some don’t.

Are you getting any errors in your output?

No errors show up, cause it only happens in public lobbies and happens “randomly”. Another solution may be having the script take away the item once u touch it? Maybe that would fix something.

Is this a server script or local script?

“:connect” is deprecated, it’s no longer supported by ROBLOX, also use “:Connect”, you didn’t make an if statement if the hit object is a character or not, it can’t find the humanoid in the parent if it doesn’t make sure it’s a character or not

Local, in a part. If needed I can make a place if you want.

it is likely that while the program is waiting you have unequipped the tool, try this:

teleportA = script.Parent.TeleportA
teleportB = script.Parent.TeleportB

teleportA.Touched:connect(function(hit)
	if canteleport == true and hit.Parent.Name == "RedGear" then
		canteleport = false
		--wait(0.2)
		hit.Parent.Parent.HumanoidRootPart.CFrame = teleportB.CFrame
		wait(1)
		canteleport = true
	end
end)```
hope this can help you

also, if a keycard touches it or the part named “RedGear” but a character isn’t holding it and it somehow happens to, it doesn’t work + show us the error output

Change it to a server script and try that

I’ll attempt to recreate the bug. Thanks.

He said that it randomly stopped, not the fact it didn’t work from the beginning, also i doubt that’ll do anything but make it visible for all players in the server.

if you have to wait, just create a variable before waiting for it contains humanoid:

local players = game:GetService("Players")

teleportA = script.Parent.TeleportA
teleportB = script.Parent.TeleportB

teleportA.Touched:connect(function(hit)
	if canteleport == true and hit.Parent.Name == "RedGear" then
		canteleport = false
                local humanoid = hit.Parent.Parent.HumanoidRootPart
		wait(0.2)
		humanoid.CFrame = teleportB.CFrame
		wait(1)
		canteleport = true
	end
end)

if that’s not okay you can say it, I’m just trying to help

1 Like

Will check up with these. Thank you!

Hmm, seems like something with the game, not the script as scripts dont really differ between servers.

Not that it differs in servers, but that something suddenly causes it to stop working, or maybe clogs it so no one can use it. Once it happens it a server, it can’t be fixed. In simple words, the tp will stop working cause of something in public games, it works normally, but wtvr the bug is happens randomly, in random servers, at random times. Of course it probably has an answer that I just haven’t found. Hope I made it a little clearer

Can you actually send the error output? This would actually make things easier than people questioning you where stuff is located, etc.