Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to prevent FilteringEnabled GUI to clone?

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

✓ Accepted answer
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)

1 comment

0

Works pretty well. Thanks.

This discussion is preserved as it was. New answers, comments, and votes are closed.