Hello,
So I am trying to make it so when the UI get’s clicked it will then run something and destroys the button. I have made this script but I am getting no error but the UI will not destroy. Not sure on how I can do it.
Script in button:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Remote = ReplicatedStorage.EpicTwo
local Button = script.Parent
Button.MouseButton1Click:Connect(function()
Remote:FireServer()
Button:Destroy()
end)
3 Likes
maybe it’s because Remote:FireServer() is empty? i’d like to replace Remote:FireServer() to Remote:FireServer(true).
*let me know if this doesn’t works
1 Like
No it still does not destroy the UI. I am really confused as it should work.
2 Likes
Hmmm… This is weird, i just tested in studio and it worked
1 Like
I will test it out on a diffrent game
1 Like
Can you send the pic of the ReplicatedStorage and the script which will receive the :FireServer()? Then i’ll check it out
1 Like
I really hope it’s all correct lol. I scripted it last night when I was half asleep. (sorry for the random veribles I could not be bothed to make up good names when I should be sleeping.
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Remote = ReplicatedStorage.EpicOne
local RemoteTwo = ReplicatedStorage.EpicTwo
local RemoteThree = ReplicatedStorage.EpicThree
local pointcount = 0
--All the annoying stuff--
Remote.OnServerEvent:Connect(function(Player)
local PlayerGui = Player:WaitForChild("PlayerGui")
local StarterUI = PlayerGui:WaitForChild("Start UI")
local BackDrop = StarterUI:WaitForChild("BackDrop")
local Image = StarterUI:WaitForChild("LighthouseLogo")
local TextButton = StarterUI:WaitForChild("ClickThingFirst")
local TextForButton = StarterUI:WaitForChild("ClickThingFirstBack")
local TraieeQuizText = StarterUI:WaitForChild("TraineeQuiz")
local WhoCreated = StarterUI:WaitForChild("CreatedByLifeDigger")
local QuestionOneUI = PlayerGui:WaitForChild("Question One")
local QuestionTwoUI = PlayerGui:WaitForChild("Question Two")
BackDropQues = QuestionOneUI:WaitForChild("BackDropQues")
QuestionOnelol = QuestionOneUI:WaitForChild("Questionone")
Box1 = QuestionOneUI:WaitForChild("Box1")
LifeDigger = QuestionOneUI:WaitForChild("LifeDigger")
dog = QuestionOneUI:WaitForChild("Box3")
cat = QuestionOneUI:WaitForChild("Noob")
pig = QuestionOneUI:WaitForChild("Lukas")
apple = QuestionOneUI:WaitForChild("Box2")
DropBack2 = QuestionTwoUI:WaitForChild("DropBack2")
No = QuestionTwoUI:WaitForChild("No")
Yes = QuestionTwoUI:WaitForChild("Yes")
Box2Yes = QuestionTwoUI:WaitForChild("Box2Yes")
Box3No = QuestionTwoUI:WaitForChild("Box3No")
BackDrop.Visible = false
Image.Visible = false
TextButton.Visible = false
TextForButton.Visible = false
TraieeQuizText.Visible = false
WhoCreated.Visible = false
BackDropQues.Visible = true
QuestionOnelol.Visible = true
Box1.Visible = true
LifeDigger.Visible = true
dog.Visible = true
cat.Visible = true
pig.Visible = true
apple.Visible = true
print("Works")
end)
RemoteTwo.OnServerEvent:Connect(function(Player)
pointcount = pointcount + 1
print(Player)
print(pointcount)
print("You did touch him")
BackDropQues.Visible = false
QuestionOnelol.Visible = false
Box1.Visible = false
LifeDigger.Visible = false
dog.Visible = false
cat.Visible = false
pig.Visible = false
apple.Visible = false
DropBack2.Visible = true
No.Visible = true
Yes.Visible = true
Box2Yes.Visible = true
Box3No.Visible = true
end)
RemoteThree.OnServerEvent:Connect(function(Player)
print(Player)
print(pointcount)
print("You did not tocun Life")
BackDropQues.Visible = false
QuestionOnelol.Visible = false
Box1.Visible = false
LifeDigger.Visible = false
dog.Visible = false
cat.Visible = false
pig.Visible = false
apple.Visible = false
end)
3 Likes
Try changing the client to Remote:FireServer(game.Players.LocalPlayer)
1 Like
Bunnyh_Script:
game.Players.LocalPlayer
But how would you effect the destroy UI part? (the script I showed u does work and run)
2 Likes
tob777
(Tob)
December 19, 2020, 5:38pm
10
There is no reason to send any arguments to the server and it will not change anything in this case. The reason the button might not be getting destroyed is because of something else.
2 Likes
Yea that is why I thought. I am not sure why though. Got any ideas?
1 Like
tob777
(Tob)
December 19, 2020, 5:40pm
12
Not too sure. Do you get any errors from the local script that could cause the button to not be destroyed? Can you destroy the button in another way and have it work just fine still? It might not be the code you provided but a seperate thing.
1 Like
I am not sure. I tried to destroy the UI in a different script but it still did not work. Let me send u all the stuff I get sent in the output. The reason why there is more then one point is because I just made the UI not visible so the button is still there when u press
1 Like
tob777
(Tob)
December 19, 2020, 5:48pm
14
Right after you destroy the button could you try adding a little print? Like
print(script.Parent)
I tested in studio and it printed nil for me as it should
Synteuro
(Synteuro)
December 19, 2020, 5:51pm
15
It will not print nil, it would error if it was because you’re attempting to index nil with :Destroy()
It comes with nil but is still there
1 Like
Synteuro
(Synteuro)
December 19, 2020, 5:52pm
17
You’re not supposed to send the LocalPlayer as the 1st argument because it is already provided on the server.
3 Likes
Synteuro
(Synteuro)
December 19, 2020, 5:53pm
18
Are you sure there aren’t any errors?
Where did you print nil? Could you show your code each time you change it?
tob777
(Tob)
December 19, 2020, 5:53pm
19
Just to confirm you’re checking PlayerGui right? if you check in StarterGui it will always be there
Synteuro
(Synteuro)
December 19, 2020, 5:54pm
20
Also, when you click it on your screen, does it actually go away? If it does then, tob is right, you’re looking at the wrong service.