Hello Friends. Thank you in advance for your support.
I am planning to create a "trivial pursuit"-like game on Roblox. I have noticed that from from any script I can create a "part" using the "instance.new" call.
The part will create, and I can set the size, position etc in real time, from any script anywhere. However, I want to create Textbuttons from a script (or localscript) and modify its attributes from anywhere too, but only works if the script parent is the button itself.
As an example, I would like to create a textbutton for each player in a game. I need to count the players first, and then create as many buttons as players exist. However I cannot make the buttons appear in screen. Here is the code I use to create the buttons from a script in inside "ScreenGui":
local boton = Instance.new("TextButton",game.StarterGui.ScreenGui)
boton.AnchorPoint = Vector2.new(0.5, 0.5)
boton.Position = UDim2.new(0.5, 0, 0.5, 0)
The boton Textbutton creates itself, it set the proper parameters to it, but you can see nothing on the game screen. Is like the button is hidden or ... just doesnt show anything.
Do you know what am I doing wrong? (note that the print output in the last line prints "Testing")
Thank you again.
Is your code in a server script or a LocalScript if its in a LocalScript, then your problem may be that you're parenting a textbutton to the starter gui when you need to be parenting it to the player gui ex:
local player = game.Players.LocalPlayer local sgui = player.PlayerGui:FindFirstChild("ScreenGui",true) if sgui then --code here end
Ok let me start off by saying you can Instance Gui's and put them inside the screen gui and change their properties, but they will not appear, you will see them in the explorer, yet they will not be visible, I am not sure why it is like this but, what you actually want to do is design the gui in studio and use a script or local script to change the visible property of the gui to true, for example I create a textbutton in studio and put it inside the screenGui and set visible to false,Then I can make a shop button with a local script to make the other textbutton visible, For example:
--Local Script(Client) script.Parent.MouseButton1Click:Connect(function() --event for when button is clicked local screenGui=script.Parent.Parent --reference to screenGui local boton=screenGui.boton2 --reference to the button you want to make visible if boton.Visible==false then --if the button isn't already visible script.Parent.Text="Close Shop" --indicates to player to close shop with the same button boton.Visible=true elseif boton.Visble==false then script.Parent.Text="Open Shop" --indicates to player that clicking will open shop boton.Visible=true end end)
Now you might use that on a frame that manages your actual shop gui. Also if you want to show a gui from the server you can, even though I don't see why you would, you can use something like this and put it in ServerScriptService:
game.Players.PlayerAdded:Connect(function(player) -- event to detect when player is added --with an argument to detect the player that was added local personalGui=player:WaitForChild("PlayerGui",10):WaitForChild("ScreenGui",10) --reference to the player's gui personalGui.WelcomeMessage.Visible=true --the gui you want to display becomes visible wait(10) --the script is idle for 10 seconds personalGui.WelcomeMessage.Visible=false --the gui you want to choose becomes invisible --you can also destroy the gui like this personalGui.WelcomeMessage:Destroy() --built-in function to destroy gui end)
Amazing guys! thank you so much. Going to try it right away. By the way, do you know any comprehensive, holistic roblox-scripting course?
Thank you for your amazing help.