Hello there, I am trying to make a thing that teleports everybody that is trying to teleport to a place to that place when an event is triggered. If you click a button, it teleports you to a part this script is inside of that is transparent and has CanCollide off but has a touched event inside it that make a value inside the player true. My problem is that the thing that teleports people only happens once, and it can't happen again. I'm pretty sure the problem is that it's a changed event inside a touched event function, and needs to be outside of it. I need to retrieve the data from the touched event to the changed event.
local TeleportService = game:GetService("TeleportService") local GameID = 5948456863 local TeleportBoolian = game.ReplicatedStorage.TeleportBoolian script.Parent.Touched:Connect(function(hit) local player = game.Players:GetPlayerFromCharacter(hit.Parent) if player then local CTB = player:FindFirstChild("CanTeleportBoolian") if CTB then print("CTB HERE") CTB.Value = true print("true") --where the code used to be end end end) --where the code is now TeleportBoolian.Changed:Connect(function() print("Teleporting Phase 1") if TeleportBoolian and CTB.Value == true then print("Teleporting Phase 2") TeleportService:Teleport(GameID, player) end end)
local TeleportService = game:GetService("TeleportService") local GameID = -1 -- change this back to your game id! local TeleportBoolian = game.ReplicatedStorage.TeleportBoolian local PlayersTable = {} local deBounce = false -- a check to stop any repeat touches in a short amount of time. script.Parent.Touched:Connect(function(hit) local player = game.Players:GetPlayerFromCharacter(hit.Parent) if player and deBounce == false then deBounce = true --// just a small hack to mkae sure the bool teleport tag exists inside the player, if it doesnt then create it! local CTB = player:FindFirstChild("CanTeleportBoolian") if(not CTB) then CTB = Instance.new("BoolValue",player) CTB.Name = "CanTeleportBoolian" end if CTB ~= nil then print("CTB HERE") CTB.Value = true -- print("true") PlayersTable[player] = CTB TeleportBoolian.Value = true -- another hack to change the server teleport tag to true on player touch --where the code used to be wait(1) deBounce = false end end end) --where the code is now TeleportBoolian.Changed:Connect(function(TeleBool) print("Teleporting Phase 1") for player,CTB in pairs(PlayersTable) do if TeleBool == true and CTB.Value == true then print("Teleporting Phase 2") print("Teleporting[",player,"]") TeleportService:Teleport(GameID, player) PlayersTable[player] = nil -- might bug out a little due to us removing the player from the same table we're working on, but should be good end end end) --[[ while true do -- a debugging loop just to see whats going on so not needed! print(TeleportBoolian.Value) wait() end ]]
So i think whats going on with things not triggering is the way we was changing the global teleport trigger. I've tried to change the value from my studio and it didnt respond so i decided to change the value from within the script and it works. I also added a deBounce check to stop any spamming of touches when you run into the teleport part.
Hope this helps you in some way :)