Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
mrcool2 75
8 years ago

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!

1
is it in a local script? DeveloperSolo 370 — 8y
0
Oh no.. It's in regular script inside a brick that the player touches mrcool2 75 — 8y

1 answer

Log in to vote
0
Answered by 8 years ago

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.

0
Yes the gui is being created perfectly fine both in studio and online, it's just when you click it nothing happens mrcool2 75 — 8y
Ad

Answer this question