Hi, im making a tower defense game and i want it to like delete a GUI if it has one, and all towers has the name ‘‘UpgradeGUI’’ how do i make it so if you click on them it deletes if there is a GUI named ‘‘UpgradeGUI’’ so it doesn’t cause GUI overlaying over upgrades.
gui = script.Parent.UpgradeTower
function onClick(click)
if click.Name == script.Parent.Parent.creator.Value then
local guicopy = gui:Clone()
guicopy.Parent = click.PlayerGui
else
workspace.error:Play()
end
end
script.Parent.ClickDetector.MouseClick:connect(onClick)
i mean like, lets say you have 2 towers right? and you click the first one, and then if you click on the second tower, it deletes that UpgradeGUI from the first one, so it doesn’t overlay on screen.
local Detector = -- choose the clickdetector in the tower
local GUI1 = First upgradegui
local GUI2 = Second upgradegui
--etc.
Detector.MouseClick:Connect(function()
GUI1.Transparency = 1
GUI2.Transparency = 0
-- Basically set all GUIs Transparency to 0 that aren't the one the player chose .
end)
This is my idea but im not sure on how to Add more GUI Variables when the user puts down more.
you can add bool values intro Rep storage for each gui and when the player for example click on gui 1 set the value of gui1 to true and when he try to open the other one check if the value of gui1 is true or not if it is then hide gui 1 if not then that means the player didn’t open any other gui’s before, do this for both.
local gui = script.Parent.UpgradeTower
local sound = workspace.error
function onClick(plr)
if plr.Name == script.Parent.Parent.creator.Value then
if plr.PlayerGui:FindFirstChild('UpgradeTower') then
plr.PlayerGui.UpgradeTower:Remove()
end
local guicopy = gui:Clone()
guicopy.Parent = plr.PlayerGui
else
sound:Play()
end
end
script.Parent.ClickDetector.MouseClick:Connect(onClick)