I am wondering how I can get my teleporters to only teleport a player only when they step off of the teleporter and step back onto it using debounce, instead of being teleported onto the other teleporter and then teleported right back.
local assetID = 870836117 local debounce = false local pad = script.Parent.Parent.Parent.TeleB.Pad local function OwnsShades(Hit) if debounce == false then debounce = true local plr = game.Players:GetPlayerFromCharacter(Hit.Parent) if plr then if game:GetService("MarketplaceService"):PlayerOwnsAsset(plr,assetID) then print(plr.Name .. " owns the Midnight Shades") Hit.Parent:MoveTo(pad.Position) else print(plr.Name .. " doesn't own the shades") game:GetService("MarketplaceService"):PromptPurchase(plr, assetID) end wait(1) debounce = false end end end script.Parent.Touched:Connect(OwnsShades)
something like this instead of debounce
script.Parent.Touched:connect(function(hit) if hit.Parent and not hit:FindFirstChild("RecentlyTeleported") then local teleportNotifier = Instance.new("StringValue") teleportNotifier.Name = "RecentlyTeleported" teleportNotifier.Parent = hit game.Debris:AddItem(teleportNotifier,2) -- however long you want to lock them out of teleportation
What I think you can use is the Disconnect method.
local assetID = 870836117 local pad = script.Parent.Parent.Parent.TeleB.Pad local event event = script.Parent.Touched:Connect(function(hit) local plr = game.Players:GetPlayerFromCharacter(hit.Parent) if plr then if game:GetService("MarketplaceService"):PlayerOwnsAsset(plr,assetID) then print(plr.Name .. " owns the Midnight Shades") hit.Parent:MoveTo(pad.Position) else print(plr.Name .. " doesn't own the shades") game:GetService("MarketplaceService"):PromptPurchase(plr, assetID) end event:Disconnect() end end )
You can learn more about it here: https://wiki.roblox.com/index.php?title=RBXScriptConnection#Disconnect
Hope this helps!