Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why does this textbutton GUI not run it's function when clicked online? [SOLVED]

The script below I have had help to build to make GUI's show for players online as you can see from this link here: https://scriptinghelpers.org/questions/25624/why-does-this-gui-script-not-work-online

However I have now encountered a problem where textboxes will not carry out their functions when clicked on when the game is played online...

function touch(hit)
	if hit.Parent:IsA('Model') then
		local player = game.Players:FindFirstChild(hit.Parent.Name)
		if player then

			local screengui = Instance.new("ScreenGui")
			screengui.Parent = player.PlayerGui

			local textbutton = Instance.new("TextButton")
			textbutton.Parent = screengui
			textbutton.Position = UDim2.new(0.07, 14, 0.73, 15)
			textbutton.Size = UDim2.new(0, 370, 0, 50)
			textbutton.BackgroundColor3 = BrickColor.White().Color
			textbutton.Text = "Click Me!"
			textbutton.BorderSizePixel = 0
			textbutton.FontSize = "Size14"
	 
			-- Bind function to button click
			textbutton.MouseButton1Down:connect(function()
				textbutton.Text = "I've been clicked!"
			end)

		elseif hit.Parent.Parent:IsA('Model') then
			local player = game.Players:FindFirstChild(hit.Parent.Parent.Name)
        	if player then
				local screengui = Instance.new("ScreenGui")
				screengui.Parent = player.PlayerGui

			local textbutton = Instance.new("TextButton")
			textbutton.Parent = screengui
			textbutton.Position = UDim2.new(0.07, 14, 0.73, 15)
			textbutton.Size = UDim2.new(0, 370, 0, 50)
			textbutton.BackgroundColor3 = BrickColor.White().Color
			textbutton.Text = "Click Me!"
			textbutton.BorderSizePixel = 0
			textbutton.FontSize = "Size14"
	 
			-- Bind function to button click
			textbutton.MouseButton1Down:connect(function()
				textbutton.Text = "I've been clicked!"
			end)
		end
	end
end

script.Parent.Touched:connect(touch)

I do not know what the problem with this is, as there is nothing showing in the output, so I have no idea...

EDIT

I managed to solve this by following the advice given in the comments and put it into a localscript, which worked a charm!

2 comments

1

is it in a local script?

0

Oh no.. It's in regular script inside a brick that the player touches

1 answer

Is the script atleast creating the gui? if not is it in a regular script or a local script? Because i do believe that it needs to be a server script so that it can detect every player that touches it then addresses their certain gui.

1 comment

0

Yes the gui is being created perfectly fine both in studio and online, it's just when you click it nothing happens

This discussion is preserved as it was. New answers, comments, and votes are closed.