Button not functioning

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

Video

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

The string is stored as such for the line you’re referring to: C#1234 and I’m attempting to get the number only.

Additionally, the print("Button clicked) part doesn’t do anything, so the function doesn’t respond. Is it because the button was created (cloned)?

No that shouldn’t prevent it.
Maybe just double check that the name isn’t “TEMPLATE” as you said you cloned it? Maybe you forgot to change the name.

If that doesn’t work maybe try putting a print in the loop itself, to see if that’s running.

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)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.