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

Button in ScreenGui is returning nil?

Asked by 5 years ago

I'm messing around with RemoteEvents at the moment, trying to get a better understanding of how it works. But I don't exactly understand why button is returning nil?

Local Script

local button = script.Parent

button.MouseButton1Click:Connect(function()
    print(button)
    game:GetService("ReplicatedStorage").TestEvent:FireServer(button)

end)

Server

local repStorage = game:GetService("ReplicatedStorage")
local event = repStorage:WaitForChild("TestEvent")

event.OnServerEvent:Connect(function(player, button)
    print(player, button)
end)

The output is Player1 nil

0
just do 'button.Name' as the argument User#23365 30 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

It is returning nil because the player gui is not accessible by the server. You can, however fire it with the button's name (button.Name).

0
So basically we're able to access all the values of button? For example like button.TextColor3 and such? Icy_Qube 29 — 5y
0
GUIs inside of the PlayerGui folder are cloned locally. The server isn't, and shouldn't be, touching GUIs anyway. And the PlayerGui folder is created by the server. User#24403 69 — 5y
Ad

Answer this question