How to create a new text label in a different gui with a button click

So I’m trying to make an ImageButton clone a TextLabel inside of a ScrollingFrame, which is also inside of another ScreenGui. Here’s what I want to achieve:

  • Passenger clicks a button
  • Button creates a new text label in a staff only panel, visible to all staff

LocalScript attempt:

local btn = script.Parent
local frame = btn.Parent.Parent.Parent.Parent.Frame
local orderframe = game.Players.LocalPlayer.PlayerGui.staffGui.staffFrame.ScrollingFrame
local plr = game.Players.LocalPlayer
local label = script.Parent.Parent

btn.MouseButton1Click:Connect(function()
	frame:TweenPosition(UDim2.new(0.5, 0, 0.05, -20), nil, Enum.EasingStyle.Sine, 2)
	wait(4)
	frame:TweenPosition(UDim2.new(0.5, 0, 0.05, -150), nil, Enum.EasingStyle.Sine, 2)
	orderframe.Order:Clone()
	local n = 1
	local newTextLabel = orderframe.Order:Clone()
	newTextLabel.TextLabel.Text = plr.Name.." | "..label.Text
	newTextLabel.Name = n..script.Parent.Parent.Text
	newTextLabel.Parent = orderframe
	n += 1
end)


orderframe.Order:Destroy()

Thank you,

  • Falcon_Aviator
1 Like

You’ll need a remote event which fires the server and then from the server you’ll need to fire all clients and then clone the TextLabel instance for each desired client (staff player).

So I tried a LocalScript somewhat like this:

local btn = script.Parent
local frame = btn.Parent.Parent.Parent.Parent.Frame
local plr = game.Players.LocalPlayer
local label = script.Parent.Parent
local event = script.Parent.Parent.Parent.Parent.Event

btn.MouseButton1Click:Connect(function()
	frame:TweenPosition(UDim2.new(0.5, 0, 0.05, -20), nil, Enum.EasingStyle.Sine, 2)
	wait(4)
	frame:TweenPosition(UDim2.new(0.5, 0, 0.05, -150), nil, Enum.EasingStyle.Sine, 2)
end)

function fire()
	event:FireServer(btn.Parent.Text)
end

btn.MouseButton1Click:Connect(fire)

Would I use another normal Script that just receives the event and fires whatever else?

Here’s something I tried

local event = script.Parent.Event
local plr = game.Players.LocalPlayer
local gui = game.StarterGui.staffGui.staffFrame.ScrollingFrame

event.OnServerEvent:Connect(function(plr, text)
	for i,v in pairs(game.Players:GetChildren()) do --this is to do this for everyone.
		local newlabel = gui.Order:Clone()
		newlabel.Parent = gui
		newlabel.Text = plr.Name..": "..text
	end
end)