Hello! So I’m creating an MDT system for a game I’m developing, and I’m trying to make it so when you click on a button, the call details (currently stored in a string value) are displayed on the UI.
The problem is that the button does not work. I don’t understand why. I tried debugging the incident and that also didn’t work. I was hoping to see if anyone knows why the button doesn’t work. I attached a video below.
Code
local player = game.Players.LocalPlayer
local frame = player.PlayerGui:WaitForChild("MDT")["Back Frame"].Calls["Call List"].ScrollingFrame
local callFrame = player.PlayerGui:WaitForChild("MDT")["Back Frame"].Calls.Details
for _, item in frame:GetChildren() do
if item:IsA("TextButton") and item.Name ~= "TEMPLATE" then
item.MouseButton1Click:Connect(function()
print("Button clicked")
if item.Data.Value ~= "" then
local id = item.Name:split("#")[1]
if callFrame.CurrentlyDisplaying.Value ~= id then
callFrame.CurrentlyDisplaying.Value = id
callFrame.Title.Text = "PD - Emergency Call"
callFrame.Status.Text = "ACTIVE"
local data = item.Data.Value:split("_")
callFrame.Location.Text = data[1]
callFrame.Description.Text = data[2]
end
end
end)
end
end
Try changing the local id line to local id = item.Name:split("#")[2], I’m pretty sure tables in lua start at 1, and what you’re doing here is comparing "Call " to the CurrentlyDisplaying value
You are only looping through your buttons once, when the script first runs. By this time there are probably no buttons so it won’t work.
Try using a childAdded event instead:
local player = game.Players.LocalPlayer
local frame = player.PlayerGui:WaitForChild("MDT")["Back Frame"].Calls["Call List"].ScrollingFrame
local callFrame = player.PlayerGui:WaitForChild("MDT")["Back Frame"].Calls.Details
frame.ChildAdded:Connect(function(item)
if item:IsA("TextButton") and item.Name ~= "TEMPLATE" then
item.MouseButton1Click:Connect(function()
print("Button clicked")
if item.Data.Value ~= "" then
local id = item.Name:split("#")[1]
if callFrame.CurrentlyDisplaying.Value ~= id then
callFrame.CurrentlyDisplaying.Value = id
callFrame.Title.Text = "PD - Emergency Call"
callFrame.Status.Text = "ACTIVE"
local data = item.Data.Value:split("_")
callFrame.Location.Text = data[1]
callFrame.Description.Text = data[2]
end
end
end)
end
end)