The table is not changed in the script what to do

now I’ll tell you what’s going on

local vkusi = {
	"Chocolate flavor",
	"Pistachio flavor",
	"Vanilla flavor",
	"Banana flavor",
}


local randomvkusvalue = game:GetService("ReplicatedStorage"):FindFirstChild("gamelogic").randomvkus;
randomvkusvalue.Value = vkusi[math.random(1,#vkusi)];
task.wait(1);
dialogue.hellotexts = {
	[1] = {
		dialoguetext = "Hello, i want to buy "..randomvkusvalue.Value.." ice cream";
		choices = {
			[1] = {
				choice = "No";
				dialoguetext = "I will write a bad review!";
			};
			[2] = {
				choice = "Okay";
				dialoguetext = "I'm waiting";
			};
		};
	},
	[2] = {
		dialoguetext = "HELLO FAST MAKE ME "..randomvkusvalue.Value.." ICE CREAM";
		choices = {
			[1] = {
				choice = "DO NOT SHOUT AT ME";
				dialoguetext = "HATE YOU";
			};
			[2] = {
				choice = "Okay";
				dialoguetext = "FASTER";
			};
		};
	},
}

Look at the beginning of the script, I change randomvkusvalue.Value = vkusi[math.random(1,#vkusi)];

And the table remembers it forever


function dialogue.opendialogueandtext(plrname,dialoguegui,icecreamtypesgui)
	randomvkusvalue.Value = vkusi[math.random(1,#vkusi)];
	task.wait(1);

but then I change the value of randomvkusvalue again but the table does not see this and still takes the previous random
:sob::sob:


how can i fix this ?

Are hellostrings defined outside of the function? If so, you must define them inside of the function.
Defining them outside of the function will mean that they keep the original value instead of the new value.

Example:

local itemValue = "YES"
local newString = "I like the word "..itemValue.."."

function printItems()
    itemValue = "NO"
    print(newString) -- This will still print "I like the word YES". Keeping the old value.
    print(itemValue) -- This will print NO.

Full Module Script:

local dialogue = {}

local isdonefunction = game:GetService("ReplicatedStorage"):FindFirstChild("gamelogic").isdonefunction;

local randomnames = {
	"James",
	"aftonskyy",
	"Scott",
	"Fgott",
	"Nvishurl",
	"Peter Parker",
	"Dr.Octupus",
	"Jeb",
	"William",
	"Notch",
	"Opium",
	"destroy lonely",
}

local vkusi = {
	"Chocolate flavor",
	"Pistachio flavor",
	"Vanilla flavor",
	"Banana flavor",
}


local randomvkusvalue = game:GetService("ReplicatedStorage"):FindFirstChild("gamelogic").randomvkus;
randomvkusvalue.Value = vkusi[math.random(1,#vkusi)];
task.wait(1);
dialogue.hellotexts = {
	[1] = {
		dialoguetext = "Hello, i want to buy "..randomvkusvalue.Value.." ice cream";
		choices = {
			[1] = {
				choice = "No";
				dialoguetext = "I will write a bad review!";
			};
			[2] = {
				choice = "Okay";
				dialoguetext = "I'm waiting";
			};
		};
	},
	[2] = {
		dialoguetext = "HELLO FAST MAKE ME "..randomvkusvalue.Value.." ICE CREAM";
		choices = {
			[1] = {
				choice = "DO NOT SHOUT AT ME";
				dialoguetext = "HATE YOU";
			};
			[2] = {
				choice = "Okay";
				dialoguetext = "FASTER";
			};
		};
	},
}

dialogue.correntends = {
	[1] = {
		dialoguetext = "Thank you!";
	},
	[2] = {
		dialoguetext = "YEAAHH";
	},
	[3] = {
		dialoguetext = "THIS IS SO DELICIOUS!";
	},
	[4] = {
		dialoguetext = "Omg Thanks!";
	},
	[5] = {
		dialoguetext = "Subscribe to afton5057 YouTube channel";
	},
}


dialogue.uncorrentends = {
	[1] = {
		dialoguetext = "hate you";
	},
	[2] = {
		dialoguetext = "I will write a bad review";
	},
	[3] = {
		dialoguetext = "This is not what I wanted!";
	},
	[4] = {
		dialoguetext = "NO! THIS IS NOT WHAT I WANTED";
	},
	[5] = {
		dialoguetext = "bro really thought i ordered this💀";
	},
}


local canhide = false;

function dialogue.typewrite(text,label)
	canhide = false;
	label.Text = "";
	for i = 1,#text,1 do
		label.Text = string.sub(text,1,i);
		task.wait(0.05);
	end
	task.wait(1);
	canhide = true;
end

function dialogue.appear(gui)
	game.TweenService:Create(gui,TweenInfo.new(.2),{Position = UDim2.new(0.218, 0,0.533, 0)}):Play();
end

function dialogue.close(gui)
	game.TweenService:Create(gui,TweenInfo.new(.2),{Position = UDim2.new(0.218, 0,2, 0)}):Play();
end

function dialogue.openicecreamtypes(gui,textlabel,dialoguegui)
	dialogue.appear(gui.Types);
	local one = gui.Types.one;
	local two = gui.Types.two;
	local three = gui.Types.three;
	local four = gui.Types.four;
	local buttons = {
		[gui.Types.one] = "Chocolate flavor",
		[gui.Types.two] = "Pistachio flavor",
		[gui.Types.three] = "Vanilla flavor",
		[gui.Types.four] = "Banana flavor",
	}
	
	local selectedButton = nil;
	for buttonType, vkus in pairs(buttons) do
		if vkus == randomvkusvalue.Value then
			selectedButton = buttonType;
			break;
		end
	end
	if selectedButton ~= nil then
		print(selectedButton);
		for i, buttons in pairs(gui.Types:GetChildren()) do
			if buttons:IsA("TextButton") then
				buttons.MouseButton1Click:Connect(function()
					if buttons.Name == selectedButton.Name then
						dialogue.close(gui.Types);
						dialogue.appear(dialoguegui.container);
						local randomends = dialogue.correntends[math.random(1,#dialogue.correntends)];
						dialogue.typewrite(randomends.dialoguetext,textlabel);
						if canhide then
							dialogue.close(dialoguegui.container);
							isdonefunction:InvokeServer();
						end
					else
						dialogue.close(gui.Types);
						dialogue.appear(dialoguegui.container);
						local randomends = dialogue.uncorrentends[math.random(1,#dialogue.uncorrentends)];
						dialogue.typewrite(randomends.dialoguetext,textlabel);
						if canhide then
							dialogue.close(dialoguegui.container);
							isdonefunction:InvokeServer();
						end
					end
				end)
			end
		end
		selectedButton.MouseButton1Click:Connect(function()
			
		end)
	else
		
	end
end

function dialogue.opendialogueandtext(plrname,dialoguegui,icecreamtypesgui)
	randomvkusvalue.Value = vkusi[math.random(1,#vkusi)];
	task.wait(1);
	dialogue.appear(dialoguegui.container);
	local choiceone = dialoguegui.container.Choiceone;
	local choicetwo = dialoguegui.container.Choicetwo;
	local TextLabel = dialoguegui.container.dialogueframe.TextLabel;
	local nametext = dialoguegui.container.Nametext;
	nametext.Text = randomnames[math.random(1,#randomnames)];
	local randomdialogue = nil;
	randomdialogue = dialogue.hellotexts[math.random(1,#dialogue.hellotexts)];
	dialogue.typewrite(randomdialogue.dialoguetext,TextLabel);
	if randomdialogue.choices then
		choiceone.Visible = true;
		choicetwo.Visible = true;
		choiceone.Text = randomdialogue.choices[1].choice;
		choicetwo.Text = randomdialogue.choices[2].choice;
		choiceone.MouseButton1Click:Connect(function()
			choiceone.Visible = false;
			choicetwo.Visible = false;
			dialogue.typewrite(randomdialogue.choices[1].dialoguetext,TextLabel);
			if canhide then
				dialogue.close(dialoguegui.container);
				isdonefunction:InvokeServer();
			end
		end)
		choicetwo.MouseButton1Click:Connect(function()
			choiceone.Visible = false;
			choicetwo.Visible = false;
			dialogue.typewrite(randomdialogue.choices[2].dialoguetext,TextLabel);
			if canhide then
				dialogue.close(dialoguegui.container);
				dialogue.openicecreamtypes(icecreamtypesgui,TextLabel,dialoguegui);
			end
		end)
	else
		choiceone.Visible = false;
		choicetwo.Visible = false;
		if canhide then
			dialogue.close(dialoguegui.container);
			randomdialogue = nil;
		end
	end
end

return dialogue;

So, as I said, instead of defining the dialogue at the top of the script, you must define it in the function after you have changed the value.
Below is a simple way to fix the problem, but below that is a better way to fix the problem.
Fixed example:

function dialogue.opendialogueandtext(plrname,dialoguegui,icecreamtypesgui)
	randomvkusvalue.Value = vkusi[math.random(1,#vkusi)];
        -- Defining the hellotexts below will mean that they update. Otherwise, you could keep them as is and use string.format.
        dialogue.hellotexts = {
	[1] = {
		dialoguetext = "Hello, i want to buy "..randomvkusvalue.Value.." ice cream";
		choices = {
			[1] = {
				choice = "No";
				dialoguetext = "I will write a bad review!";
			};
			[2] = {
				choice = "Okay";
				dialoguetext = "I'm waiting";
			};
		};
	},
	[2] = {
		dialoguetext = "HELLO FAST MAKE ME "..randomvkusvalue.Value.." ICE CREAM";
		choices = {
			[1] = {
				choice = "DO NOT SHOUT AT ME";
				dialoguetext = "HATE YOU";
			};
			[2] = {
				choice = "Okay";
				dialoguetext = "FASTER";
			};
		};
	},
}

	task.wait(1);
	dialogue.appear(dialoguegui.container);
	local choiceone = dialoguegui.container.Choiceone;
	local choicetwo = dialoguegui.container.Choicetwo;
	local TextLabel = dialoguegui.container.dialogueframe.TextLabel;
	local nametext = dialoguegui.container.Nametext;
	nametext.Text = randomnames[math.random(1,#randomnames)];
	local randomdialogue = nil;
	randomdialogue = dialogue.hellotexts[math.random(1,#dialogue.hellotexts)];
	dialogue.typewrite(randomdialogue.dialoguetext,TextLabel);
	if randomdialogue.choices then
		choiceone.Visible = true;
		choicetwo.Visible = true;
		choiceone.Text = randomdialogue.choices[1].choice;
		choicetwo.Text = randomdialogue.choices[2].choice;
		choiceone.MouseButton1Click:Connect(function()
			choiceone.Visible = false;
			choicetwo.Visible = false;
			dialogue.typewrite(randomdialogue.choices[1].dialoguetext,TextLabel);
			if canhide then
				dialogue.close(dialoguegui.container);
				isdonefunction:InvokeServer();
			end
		end)
		choicetwo.MouseButton1Click:Connect(function()
			choiceone.Visible = false;
			choicetwo.Visible = false;
			dialogue.typewrite(randomdialogue.choices[2].dialoguetext,TextLabel);
			if canhide then
				dialogue.close(dialoguegui.container);
				dialogue.openicecreamtypes(icecreamtypesgui,TextLabel,dialoguegui);
			end
		end)
	else
		choiceone.Visible = false;
		choicetwo.Visible = false;
		if canhide then
			dialogue.close(dialoguegui.container);
			randomdialogue = nil;
		end
	end
end

string.format example (better way of doing it in my opinion):

local currentValue = Instance.new("StringValue")
currentValue.Parent = game.ServerStorage
currentValue.Value = "Taco"
local text = "Could I please have a %s?" -- %s means that a string variable will substitute that area.

function orderItem()
	currentValue.Value = "Ice-cream"
	print(string.format(text, currentValue.Value)) -- Result: Could I please have a Ice-cream?
	string.format(text, currentValue.Value)
end
orderItem()

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