TextButton Active and Activated not working

I made a dialogue system a few months ago I recently just noticed that the textButtons are kinda glitched out.


This part of the script handles whether or not the textButtons should actually be turned on or not, problem with the code is that its not actually turning anything off?

Here the output shows that the script is getting where it needs to and knows which response is which (Yes, the response button vars are set to the players gui and not startergui)

And yet the workspace says other-wise.

The other issue is with Activated, along with Active being weird on me clicking on response two which should’ve been the only active response does actually run the Activated Connect function, but pressing on the two that were supposed to be inactive do actually output something

If anybody knows why any of this is happening please respond, I have zero clues as to why my buttons have decided to go rogue on my script

You are handling this on the client, correct?

1 Like

Yeah, whole script is on the client

1 Like

Why are there multiple text buttons? Consider storing a table of strings, loop through that table, and change the text like that all to one text button

There are multiple buttons so I can have multiple responses up at the same time for the player to chose from
image

i just tested this and it seems to be working.

local responseEvent = nil;

for i, response in ipairs(script.Parent:GetChildren()) do
	responseEvent[i] = response.Activated:Connect(function()
		response.Text = "this response"
		if responseEvent then
			responseEvent:Disconnect();
			responseEvent = nil;
		end;
	end);
end;

Screenshot_8

1 Like

hm, this still doesnt really explain why the first part of the script isnt setting the responses active to false during this loop


Or why one of the active response buttons arent actually sending out a signal to connect to event

Thanks for the coding tip though, once I figure out my initial problems I’ll try what you’ve done and see if I can properly place it into my own code

You just want them to click one response and then that response determines the next piece of string that is given?

Correct, when one is pressed it checks for dialogue within the response and repeats over and over via this system I made based on one I saw on Unity, Im not sure if it’s the best way to do this but hey, it works and its progress
image

It would be better to organize this in a table within your script or require a separate module that returns information. I have created a single dialogue response, I will try to create a second dialogue to make it easier to replicate on to your script.

local responseEvent = nil;
local responses = {
	"response1",
	"response2",
	"response3"
};
for i, response in ipairs(script.Parent:GetChildren()) do
	if response:IsA("TextButton") then
		responseEvent = response.Activated:Connect(function()
			script.Parent.TextLabel.Text = responses[i]
			response.Text = "this response"
			if responseEvent then
				responseEvent:Disconnect();
				responseEvent = nil;
			end;
		end);
	end;
end;
1 Like

Ah I see but wait wait wait, we keep getting off track. Right now I am worried that Im using the TextButtons .Active and .Activated:Connected wrong, I still have no idea why the actives aren’t being set to false and why Activate functions arent connecting. I really appreciate the organizations and better code choices and I’ll definitely come back to them when I revamp the code but I still need figure out why my code that used to be working no longer isnt

1 Like

Are you setting active back to true when the dialogue replies?

I think I’ve created something similar to your dialogue system, it doesn’t set active to false, but just runs the function again. You could add a debounce in place of disabling the button, still not too sure of what is wrong with your code, you could send me a script if you’d like. Here’s my code.

local responseEvent = nil;
local indent = 1;
local lastResponse = nil;
local responses = {
	[1] = {
		["Default"] = "response1",
		[1] = "response1, 1",
		[2] = "response1, 2",
		[3] = "response1, 3"
	},
	[2] = {
		["Default"] = "response2",
		[1] = "response2, 1",
		[2] = "response2, 2",
		[3] = "response2, 3"
	},
	[3] = {
		["Default"] = "response3",
		[1] = "response3, 1",
		[2] = "response3, 2",
		[3] = "response3, 3"
	}
};
local function callResponse()
	for i, response in ipairs(script.Parent:GetChildren()) do
		if response:IsA("TextButton") then
			responseEvent = response.Activated:Connect(function()
				if (lastResponse == nil) then
					script.Parent.TextLabel.Text = responses[i]["Default"];
					lastResponse = i;
					callResponse();
				else
					script.Parent.TextLabel.Text = responses[lastResponse][i];
				end;

				response.Text = "this response";

				if responseEvent then
					responseEvent:Disconnect();
					responseEvent = nil;
				end;
			end);
		end;
	end;
end;

callResponse()

Hey! Sorry for the really late response, I wasn’t able to get on over the weekend. I copied over everything related to the dialogue system into a separate game and it has started to work. I’ll send the dialogue system in-case you’re still curious. I’d move this into the Studio Bugs section but sadly I dont have access to creating topics in there.
InteractionTest.rbxl (77.4 KB)