This script was working the other day and now it’s not. It is supposed to fire an event corresponding with the button’s name when the player clicks. I did this so I didn’t have to have a script under each button so that it is more efficient.
Also, there are no errors in the output.
Script:
local plr = game.Players.LocalPlayer
local rep = game:GetService("ReplicatedStorage")
local function BindButtonToFunction(button, func)
button.MouseButton1Click:Connect(func)
end
for _,v in pairs (script.Parent:GetChildren()) do
if v:IsA("TextButton") then
if plr.Name == rep:FindFirstChild("CurrentMaster").Value then
BindButtonToFunction(v, function()
local event = rep.ControlPanelEvents:FindFirstChild(v.Name)
print("found button time to fire")
event:FireServer()
end)
end
end
end
try printing stuff inbetween all the lines and see the ones that aren’t printing. If I had to guess it could be your function you created, but I doubt that.
I don’t really know what you mean by that. I changed my script to this and it’s still not doing anything (I check and the script is still enabled)
local plr = game.Players.LocalPlayer
local rep = game:GetService("ReplicatedStorage")
local mouse = plr:GetMouse()
mouse.Button1Down:Connect(function()
for _,v in pairs (script.Parent:GetChildren()) do
if v:IsA("TextButton") then
if plr.Name == rep:FindFirstChild("CurrentMaster").Value then
--BindButtonToFunction(v, function()
v.MouseButton1Click:Connect(function()
local event = rep.ControlPanelEvents:FindFirstChild(v.Name)
print("found button time to fire")
event:FireServer()
end)
end
end
end
end)
local plr = game.Players.LocalPlayer
local rep = game:GetService("ReplicatedStorage")
local mouse = plr:GetMouse()
mouse.Button1Down:Connect(function()
for _,v in pairs (script.Parent:GetChildren()) do
if v:IsA("TextButton") then
if plr.Name == rep:FindFirstChild("CurrentMaster").Value then
local connection
connection = v.MouseButton1Click:Connect(function()
local event = rep.ControlPanelEvents:FindFirstChild(v.Name)
print("found button time to fire")
event:FireServer()
connection:Disconnect()
end)
end
end
end
end)
Just click in the left of the line number. Then press play and try to active your function.
Game gonna pause and you can see what’s wrong, put your mouse in a variable and you gonna see if it exists.
Just like this.
Try to debug yours if statements maybe there’s a value that didnt exist there.
Well, I even put a print() right after the button1down function and it didn’t print anything, so I almost feel like something is wrong with the button itself I have no idea
local plr = game:GetService("Players").LocalPlayer
local rep = game:GetService("ReplicatedStorage")
for i, v in pairs(script.Parent:GetChildren()) do
if v:IsA("TextButton") then
v.MouseButton1Click:Connect(function()
if rep:FindFirstChild("CurrentMaster").Value == plr.Name then
rep.ControlPanelEvents[v.Name]:FireServer()
end
end)
end
end