im trying to avoid adding a script on every button to keep it simple and not that laggy, is there a way that can detects which button is cicked based on the button name?
ive tried this so far, i found it in the devforum but it sadly didn’t work
its a local script
local re = game.ReplicatedStorage:WaitForChild("CharacterRE")
script.Parent.DescendantAdded:Connect(function(Descendant)
if Descendant:IsA("ViewportFrame") then
if Descendant:FindFirstChild("Button") then
Descendant.Button.MouseButton1Click:Connect(function()
re:FireServer(Descendant.Name)
end)
end
end
end)
the button is child to a viewportframe, that makes the viewport frame able to be clicked
I want it to fire the name of the viewport frame when the button inside it is clicked
local re = game.ReplicatedStorage:WaitForChild("CharacterRE")
script.Parent.DescendantAdded:Connect(function(Descendant)
if Descendant:IsA("TextButton") or Descendant:IsA("ImageButton") then
Descendant.MouseButton1Click:Connect(function()
re:FireServer(Descendant.Name)
end)
end
end)
local re = game.ReplicatedStorage:WaitForChild("CharacterRE")
for Index,Descendant in pairs(script.Parent:GetDescendants()) do
if Descendant:IsA("TextButton") or Descendant:IsA("ImageButton") then
Descendant.MouseButton1Click:Connect(function()
re:FireServer(Descendant.Name)
end)
end
end
I changed the re:FireServer(Descendant.Name)
to re:FireServer(Descendant.Parent.Name)
since I want it to fire the name of the viewport frame, but it works fine