Trying to make a text system like Isle's, but having issues with marking the current text

I want to make a text system like Isle’s, where when an action is performed, it makes dialogue appear, and if it is repeated, depending on where the text is, it says “Action Text [x2]”, the problem I’m having is I can’t figure out how to differentiate from what is the current text I’m using from the one I’m comparing to, which has given me huge issues.

I’ve tried using an IntValue named “Current” but the problem is, when I try to delete the IntValue, it just doesn’t destroy it.
The weird part is when I put “current:Destroy()” at the top, like this, it works.

game.ReplicatedStorage.Dialogue.OnClientEvent:Connect(function(text, color)
	print(text)
	local clone = textFrame:Clone()
	clone.Parent = script.Parent
	clone.Name = text
	clone.TextLabel.Text = text
	clone.TextLabel.TextColor3 = color
	local current = Instance.new("IntValue")
	current.Name = "Current"
	current.Parent = clone
        current:Destroy() -- here

But if I put it below everything else (which is where I need it), it doesn’t delete the IntValue.

game.ReplicatedStorage.Dialogue.OnClientEvent:Connect(function(text, color)
	print(text)
	local clone = textFrame:Clone()
	clone.Parent = script.Parent
	clone.Name = text
	clone.TextLabel.Text = text
	clone.TextLabel.TextColor3 = color
	local current = Instance.new("IntValue")
	current.Name = "Current"
	current.Parent = clone

	if script.Parent[text] then
		if script.Parent[text].Current then return end
		if script.Parent[text].Position == UDim2.new(0.5, 0, 0.5, 0) then
			local thing = script.Parent[text]
			if thing:FindFirstChild("RepeatCounter") then
			

			thing.RepeatCounter.Value += 1
			thing.Visible = true
			thing.TextLabel.Text = text.." [x"..tostring(thing.RepeatCounter.Value).."]"
			else
			local repeatCounter = Instance.new("IntValue")
			repeatCounter.Name = "RepeatCounter"
			repeatCounter.Parent = thing
			thing.RepeatCounter.Value += 1
			thing.Visible = true
			thing.TextLabel.Text = text.." [x"..tostring(thing.RepeatCounter.Value).."]"
			end
		end
		
	end
	current:Destroy()
	for _, v in pairs(script.Parent:GetChildren()) do
		if v:IsA("Frame") then
			if v.Name ~= text then
			local pos = UDim2.new(v.Position.X.Scale, v.Position.X.Offset, v.Position.Y.Scale, v.Position.Y.Offset)
			v:TweenPosition(pos + UDim2.new(0, 0, 0, -30), Enum.EasingDirection.Out, Enum.EasingStyle.Back, 0.3, true)
			end
		end
	end
     current:Destroy() -- here
end)

If theres any way to fix this I’d like to know.

You destroyed it twice? Add a print statement before the destroy to check if the script even reaches that part

I didn’t destroy it twice, sorry for the confusion, I was moving them around to test if they worked at different points and they didnt, as for the print thing, I just tried that and it seems to not get past the initial check between it, I’ve tried fixing it with an else statement but it seems to just not get there.

1 Like

I think this is what stops it

if script.Parent[text].Current

You end the function there, you need to change it so it can give the next time and then end the function

That statement is there to stop it from destroying the current text that the script is referring to, if I remove that it will destroy the current text, which makes it so nothing appears.