Ad
Log in to vote
0

Button in ScreenGui is returning nil?

Asked by 3 days 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 EXpodo1234ALT 684 — 3d

1 answer

Log in to vote
0
Answered by 3 days 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 11 — 3d
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. sjr04Alt 52 — 3d
Ad

Answer this question