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

How do I fix the problems with my debouncing?

Asked by
Hasburo 150
8 years ago
-- [[ Variable Storage ]] --

local CommonTrigger = game.Workspace:FindFirstChild("CommonTrigger")

-- [[ Code ]] --

game.Players.PlayerAdded:connect(function(Player)
    local DebounceValue = Instance.new("BoolValue", Player)
    DebounceValue.Name = "DebounceValue"
    DebounceValue.Value = false
end)

function onTouched(hit)
    local Humanoid = hit.Parent:FindFirstChild("Humanoid")
    local Player = Players:GetPlayerFromCharacter(hit.Parent)
    if Player.DebounceValue.Value == false then
    Player.DebounceValue.Value = true
    Humanoid.WalkSpeed = 0
    local CommonUI = ReplicatedStorage:FindFirstChild("PT_UI").CommonUI:Clone()
    CommonUI.Parent = Player.PlayerGui
    CommonUI.Frame:TweenPosition(UDim2.new(0.5,-350,0.5,-200), "Out", "Elastic", 3)
    end
end

CommonTrigger.Touched:connect(onTouched)

The point of this script is to give every player a DebounceValue once they join the game. If they touch a certain brick, then a UI will slide down.

Now everything works fine and dandy EXCEPT my debounce method. If they touch the brick, it gives them like five of the same GUI, even with the debounce.

Before you ask why I did a BoolValue for Debounce, I honestly forgot why, but if you want to improve it or get rid of it, feel free.

Answers would be greatly appreciated!

1 answer

Log in to vote
1
Answered by
Sublimus 992 Moderation Voter
8 years ago
Edited 8 years ago

I would personally just use findFirstChild() to see if a Gui is already there.

-- [[ Variable Storage ]] --

local CommonTrigger = game.Workspace:FindFirstChild("CommonTrigger")

-- [[ Code ]] --

function onTouched(hit)
    local Humanoid = hit.Parent:FindFirstChild("Humanoid")
    local Player = Players:GetPlayerFromCharacter(hit.Parent)
    if not Player.PlayerGui:findFirstChild("CommonUI") then -- If the PlayerGui does not contain the CommonUI
    Humanoid.WalkSpeed = 0
    local CommonUI = ReplicatedStorage:FindFirstChild("PT_UI").CommonUI:Clone()
    CommonUI.Parent = Player.PlayerGui
    CommonUI.Frame:TweenPosition(UDim2.new(0.5,-350,0.5,-200), "Out", "Elastic", 3)
    end
end

CommonTrigger.Touched:connect(onTouched)

:FindFirstChild()

Ad

Answer this question