So basically as you see it clones multiple times. I basically want it so that it does not do that and only replicates it once.
local Prox = script.Parent
local GUI = script.Parent:FindFirstChildOfClass("ScreenGui")
Prox.Touched:Connect(function(hit)
local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
local Clone = GUI:Clone()
Clone.Parent = Player.PlayerGui
Prox.TouchEnded:Connect(function(hit2)
if hit == hit2 then
game.Debris:AddItem(Clone, 0)
end
end)
end)
Ohhhh wait I misunderstood you for just wanting the gui to stay once… lol
Try doing something like
local Prox = script.Parent
local GUI = script.Parent:FindFirstChildOfClass("ScreenGui")
local cloned = false
Prox.Touched:Connect(function(hit)
local Player = game.Parent:GetPlayerFromCharacter(hit.Parent)
local Clone = GUI:Clone()
if cloned == false then
Clone.Parent = Player.PlayerGui
cloned = true
end
Prox.TouchedEnded:Connect(function(hit2)
if hit == hit2 then
game.Debris:AddItem(Clone, 0)
end
end)
end)
local Players = game:GetService("Players")
local Part = script.Parent
local Gui = Part:FindFirstChildOfClass("ScreenGui")
Part.Touched:Connect(function(Hit1)
local HitModel = Hit1:FindFirstAncestorOfClass("Model")
if HitModel then
local HitPlayer = Players:GetPlayerFromCharacter(HitModel)
if HitPlayer then
local PlayerGui = HitPlayer.PlayerGui
if PlayerGui:FindFirstChild(Gui.Name) then
return
end
local GuiClone = Gui:Clone()
GuiClone.Parent = HitPlayer.PlayerGui
Part.TouchedEnded:Connect(function(Hit2)
if Hit1 == Hit2 then
GuiClone:Destroy()
end
end)
end
end
end)
There’s a good chance your script in its current state will error, also it’s better to check if the player’s “PlayerGui” folder contains the gui in question rather than using a state variable/flag to determine as such.