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

How to prevent FilteringEnabled GUI to clone?

Asked by 6 years ago

What I want is when the player touches the part, the ScreenGui clones in the player's PlayerGui. When the ScreenGui is in the PlayerGui it Tweens to a certain position. (Only one ScreenGui can appear though), this is my code:

local s = script.Parent

s.Touched:connect(function(part)
      local human = part.Parent:findFirstChild("Humanoid") 
        if human then
            local player = game.Players:GetPlayerFromCharacter(human.Parent) 
                if player then -- player touched part
                    script.Parent.RemoteEvent:FireClient(player)
                    local PlayerGui = game.Players.LocalPlayer.PlayerGui
                    local Gui = game.ReplicatedStorage:FindFirstChild("KeyController")
                    Gui:Clone().Parent = PlayerGui
         end
end
end)

The problem is when I step on the part and move a little - so many ScreenGui's are cloning into my PlayerGui. I don't want that, I only want one to display.

Also, this is my movement script (TweenPosition):

local s = script.Parent
local PlayerGui = game.Players.LocalPlayer.PlayerGui

function Tween()
    s:TweenPosition(UDim2.new(1,0,0,0), "Out", "Quad", 3, false)
end

    if s.Parent.Parent == PlayerGui then
        Tween()
end

1 answer

Log in to vote
0
Answered by 6 years ago
local s = script.Parent
local debounce = false

s.Touched:connect(function(part)
if not debounce then
debounce = true
      local human = part.Parent:findFirstChild("Humanoid") 
        if human then
            local player = game.Players:GetPlayerFromCharacter(human.Parent) 
                if player then -- player touched part
                    script.Parent.RemoteEvent:FireClient(player)
                    local PlayerGui = game.Players.LocalPlayer.PlayerGui
                    local Gui = game.ReplicatedStorage:FindFirstChild("KeyController")
                    Gui:Clone().Parent = PlayerGui
         end
end
wait(1)
debounce = false
end
end)

0
Works pretty well. Thanks. Florian27 76 — 6y
Ad

Answer this question