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 5 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.

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)
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 — 5y

2 answers

Log in to vote
1
Answered by 5 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 — 5y
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 — 5y
Ad
Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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!

0
I don't mean to be petty here but Disconnect is not an event and shouldn't be confused with one Vulkarin 581 — 5y
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 — 5y
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 — 5y
0
Whoops, I’ll write that back Syntax_404 37 — 5y

Answer this question