Hello i want to make a script that when the player click on a button, it print “Button has been clicked!” and after 2 seconds a frame with “Have fun” wrote in it appears while 4seconds. The problem is that when i click on the button the print text appears on the console but the frame with the text doesn’t appears.
local soundbutton = script.Parent
local Fun = game.StarterGui.HaveFuntext
function onClicked()
print("Button has been clicked !")
wait(2)
Fun.Enabled = false
wait(4)
Fun.Enabled = true
end
soundbutton.MouseClick:Connect(onClicked)
This is because of this line: game.StarterGui.HaveFuntext
Each player has their own PlayerGui and using StarterGui wouldn’t change it for the player.
Assuming you’re using a Script: Script
local soundbutton = script.Parent
function onClicked(player)
local Fun = player.PlayerGui.HaveFuntext
print("Button has been clicked !")
wait(2)
Fun.Enabled = false
wait(4)
Fun.Enabled = true
end
soundbutton.MouseClick:Connect(onClicked)
local soundbutton = script.Parent
function onClicked(player)
local Fun = player.PlayerGui.HaveFuntext
print("Button has been clicked !")
wait(2)
Fun.Enabled = true
wait(4)
Fun.Enabled = false
end
soundbutton.MouseClick:Connect(onClicked)
And also @Txppin, please don’t copy the script without making any changes. You’re promoting malpractices such as unnecessary :WaitForChild() usage as well as using unnecessary functions such as :FindFirstChildOfClass(). In this situation, it’s not needed.
Just in case you didn’t really understand how StarterGuis and PlayerGuis work.
When you join the game, a copy of everything in the StarterGui is put in your PlayerGui. You can only see and click the stuff in your PlayerGui, not the stuff in the StarterGui. Go test this out for yourself. Playtest, and you will see your player has been added to the Players folder. Now inside your player, there is a folder called “PlayerGui”. If you check in your PlayerGui, you will see a copy of everything in the StarterGui. Now, if you mess around with stuff in StarterGui, you won’t notice any changes. But if you mess around with stuff in your PlayerGui, you will see the changes.