How can I destroy a gui on all playergui’s if someone clicks a textbutton?
I have a frame in the playergui. I want to destroy it on all playerguis when a textbutton is clicked. How would I go about doing this? I have tried using remote events and scripts but to no help.
9 Likes
Try something like
LocalScript:
local Button = script.Parent -- assuming this script is a child of a TextButton
local Remote = game.ReplicatedStorage:WaitForChild("Remote Event Name Here")
local Frame = nil -- Replace "nil" with the frame's directory
Button.MouseButton1Click:Connect(function()
Remote:FireServer()
end)
Remote.OnClientEvent:Connect(function()
Frame:Destroy()
end)
ServerScript:
local Remote = game.ReplicatedStorage:WaitForChild("Remote Event Name Here")
Remote.OnServerEvent:Connect(function(player)
Remote:FireAllClients()
end)
4 Likes
This helped. I modified it a little bit, but I have multiple clones of the gui im trying to delete and I only want to delete one of them, but since I am firing a remote event it deletes all of them? Do you know how to fix this? My code is:
local Button = script.Parent.Close – assuming this script is a child of a TextButton
local Remote1 = game.ReplicatedStorage:WaitForChild(“ReportClose1”)
local Remote2 = game.ReplicatedStorage:WaitForChild(“ReportClose2”)
Button.MouseButton1Click:Connect(function()
Remote1:FireServer()
end)
Remote2.OnClientEvent:Connect(function()
script.Parent.Parent:Destroy()
end)
– The guis are different names but the local script causes them to all delete.
2 Likes
local Button = script.Parent.Close – assuming this script is a child of a TextButton
local Remote1 = game.ReplicatedStorage:WaitForChild(“ReportClose1”)
local Remote2 = game.ReplicatedStorage:WaitForChild(“ReportClose2”)
Button.MouseButton1Click:Connect(function()
Remote1:FireServer() -- you can pass the name of the gui as an argument (Remote1:FireServer("Gui Name") etc...)
end)
Remote2.OnClientEvent:Connect(function(name) -- if you do pass an argument back then, be sure to create a variable to define it. If you didn't then leave it blank
script.Parent.Parent:Destroy() -- if the guis are all parented to this object, then they'd all be deleted, otherwise, do "script.Parent.Parent:FindFirstChild(name):Destroy()"
end)
If you modified the server code, what does it look like
1 Like
[quote=“HugeCoolboy2007, post:5, topic:804441”]
Remote1:FireServer() -- you can pass the name of the gui as an argument (Remote1:FireServer("Gui Name") etc...)
[/quote] This would work but there is no specific name. I am making a ticket system and each gui has a new name, it is “Report Number #” and I need a way to check the name of the report I want to delete and only delete that one. I dont specify the name because the tickets are created in game.
What does the gui look like in the explorer
When it is duplicated or in studio when it is a single gui?
when it is duplicated on screen
wait, is the localscript a single localscript or is it a child to each of the frame guis
A child of each of the Frames. Also I am getting a picture
“Report Close” is the server script.
Okay, try this
local Button = script.Parent.Close – assuming this script is a child of a TextButton
local Remote1 = game.ReplicatedStorage:WaitForChild(“ReportClose1”)
local Remote2 = game.ReplicatedStorage:WaitForChild(“ReportClose2”)
Button.MouseButton1Click:Connect(function()
Remote1:FireServer(script.Parent.Name) -- be sure to pass this argument back to Remote2 through "Report Close"
end)
Remote2.OnClientEvent:Connect(function(name)
script.Parent.Parent:FindFirstChild(name):Destroy()
end)
Report Close:
local Remote1 = game.ReplicatedStorage:WaitForChild(“ReportClose1”)
local Remote2 = game.ReplicatedStorage:WaitForChild(“ReportClose2”)
Remote1.OnServerEvent:Connect(function(player,name)
Remote2:FireAllClients(name)
end)
Is this what I should do? (SErver script)
1 Like
yes _____ (i have to extend the character count to reply)
1 Like
It is working perfect just keeps giving me an error in console.
[21:12:19.417 - Players.CanadianAviatorRBX.PlayerGui.Frame.Frame.LocalScript:11: attempt to index nil with ‘Destroy’]
21:12:19.418 - Stack Begin
[21:12:19.418 - Script ‘Players.CanadianAviatorRBX.PlayerGui.Frame.Frame.LocalScript’, Line 11
21:12:19.418 - Stack End
try replacing the old Remote2 Client Event with this
Remote2.OnClientEvent:Connect(function(name)
print(tostring(name))
local frame = script.Parent.Parent:FindFirstChild(name)
if frame then
frame:Destroy()
end
end)
Edit: see if it prints the correct name. If it doesn’t then check to see if any of the children in the frame has any names of the frame’s properties
1 Like
Wow Thanks for your help! It finally works. Do you want any credits for helping with it?
no thanks, I just like to help people ![:slight_smile: :slight_smile:](https://doy2mn9upadnk.cloudfront.net/images/emoji/twitter/slight_smile.png?v=12)
1 Like
Hey. I got another question. How would I make it so the gui is only visible to people on the certain “STAFF” team? I have tried different options in scripting helpers and it hasnt helped. I want to make it visible to people on the staff team when they switch, and when they switch back, I want it to be invisible.
(Screengui Enabled/Disabled)