Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to set up Debounce so teleporters don't take player back and forth constantly?

Asked by 6 years ago

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.

01local assetID = 870836117
02local debounce = false
03local pad = script.Parent.Parent.Parent.TeleB.Pad
04 
05local function OwnsShades(Hit)
06if debounce == false then
07    debounce = true
08 
09    local plr = game.Players:GetPlayerFromCharacter(Hit.Parent)
10    if plr then
11        if game:GetService("MarketplaceService"):PlayerOwnsAsset(plr,assetID) then
12            print(plr.Name .. " owns the Midnight Shades")
13            Hit.Parent:MoveTo(pad.Position)                    
14        else
15            print(plr.Name .. " doesn't own the shades")
View all 25 lines...
0
If I am understanding correctly, you would use magnitude property to check the distance from the player to the teleport pad or whatever. Use repeat wait loop until the distance is greater than desired amount. Zafirua 1348 — 6y

2 answers

Log in to vote
1
Answered by 6 years ago

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

0
Could you give me a breakdown of what this code does? GlobeHousee 50 — 6y
0
Sorry, didn't see your comment sooner. Basically, it just searches for a value inside the player named RecentlyTeleported (or whatever you want to call it), and if they don't have it, then teleport them and create a value and put it inside the part that touches it. game.Debris:AddItem(x,y) is basically like wait(2) and then :Destroy() but won't interfere with the script. masterblokz 58 — 6y
Ad
Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

What I think you can use is the Disconnect method.

01local assetID = 870836117
02 
03local pad = script.Parent.Parent.Parent.TeleB.Pad
04 
05local event
06event = script.Parent.Touched:Connect(function(hit)
07 
08 
09 
10    local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
11    if plr then
12        if game:GetService("MarketplaceService"):PlayerOwnsAsset(plr,assetID) then
13            print(plr.Name .. " owns the Midnight Shades")
14            hit.Parent:MoveTo(pad.Position)                    
15        else
View all 25 lines...

You can learn more about it here: https://wiki.roblox.com/index.php?title=RBXScriptConnection#Disconnect

Hope this helps!

0
I don't mean to be petty here but Disconnect is not an event and shouldn't be confused with one Vulkarin 581 — 6y
0
Exactly as Vulkarin said. Disconnect is not an event but a method. Also. the `print ("Event Disconnect") will never run since you disconnected the function above it. . Zafirua 1348 — 6y
0
I mean this does stop the player from teleporting back, but it also stops the player from teleporting back. I should have clarified that this is between two teleporters, and I wanted players to be able to teleport back and forth between them, but the teleporters should only teleport the player once they get off the teleporter and back on again. GlobeHousee 50 — 6y
0
Whoops, I’ll write that back Syntax_404 37 — 6y

Answer this question