Ok so im making a game that you can buy houses but I want the forsale sign to open a gui when the click the button please help?
script.Parent.ClickDetector.MouseClick:connect(function() local gui = game.StarterGui.HouseBuy.BuyHouse gui.Visible = true end)
it is a simple script But I can't to seem how this works
You're trying to change the Visibility value of an object in StarterGui which does not replicate to all players or even a specific player instantaneously.
StarterGui is what it is, it's a Starter. Whenever your character respawns it will see the changes. However with your code, you would want to have the Gui show up for a specific person. What the Clicked event provides is a way to get the player object. Whenever a player clicks on a part, then the ClickDetector will get the player who clicked it. You can then use that object and start using the PlayerGui object of all players. PlayerGui is what a player would see on screen, manipulating it for one player will only make it visible to that player. Basically saying that GUI can only be seen by that client.
script.Parent.ClickDetector.MouseClick:connect(function(PlayerWhoClicked) --The MouseClick event will automatically give the player parameter to the function. local gui = PlayerWhoClicked.PlayerGui.BuyHouse gui.Visible = true end)
Your code has no protections of it, so if you were to click on the sign and you did not have a PlayerGui object in your player then the script would error. Or even if the names of the objects were changed.
script.Parent.ClickDetector.MouseClick:connect(function(player) local gui = game.ReplicatedStorage.HouseBuy:clone() gui.Parent = player.PlayerGui gui.BuyHouse.Visible = true end)
hi i also moved the gui to replicated storage since putting it in startergui isnt really practical, do note that the problem was that your gui wasn being cloned into the players startergui, so he isn't seeing it
script.Parent.ClickDetector.MouseClick:connect(function(player) local gui = player.PlayerGui.HouseBuy.BuyHouse gui.Visible = true end)
but if you insist on keeping it in the startergui, you can use the code above instead, it points to the playergui where the gui is kept because of the startergui's function
Here:
script.Parent.ClickDetector.MouseClick:connect(function(click) -- Put click here if click then local Click = click.Name for i, v in pairs(game.Players:GetChildren())do if v:IsA("Player") and v.Name == Click then v.PlayerGui.HouseBuy.BuyHouse.Visible = true end end end end)
You were changing the Visibility of the Gui in StarterGui instead of PlayerGui which is where the Gui would be when you play the game as StarterGui puts all it's children into the Players' PlayerGui.
You can make it like that
function onClicked() local gui = game.StarterGui.HouseBuy.BuyHouse gui.Visible = true end script.Parent.ClickDetector.MouseClick:connect(onClicked)
:)