Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

String Value Not Changing?

alright so a lot of things going on here but the issue im trying to solve at the moment is line 23 it doesnt bother changing the string value at all and just continues with the rest of the code

Script:

local textLabel = script.Parent.NPCText
local text = script.Parent.Words.Value
local length = string.len(text)
local Option1 = textLabel.Option1
local Option2 = textLabel.Option2
local stringvalue = "Sherman"
local player = textLabel.Parent.Parent.Parent
for stop = 1, length do
    wait(0.1)
  	textLabel.Text = string.sub(text, 1, stop)
	Option1.Visible = true
	Option2.Visible = true
end

script.Parent.Words.Changed:Connect(function()
	for no = 1, length do
		wait(.1)
		textLabel.Text = string.sub(text, 1, no)
	end
end)

Option1.MouseButton1Click:Connect(function()
	text = "Oh Brilliant! Please Hand Him Over!"
	Option1.Visible = false
	Option2.Visible = false
	wait(2)
	textLabel.Parent:Destroy()
end)

Option2.MouseButton1Click:Connect(function()
	Option1.Visible = false
	Option2.Visible = false
	text = "Ah I See, Well Would You Please Search For Him For Me?"
	game.ReplicatedStorage.QuestStatus:FireClient(player,stringvalue)
	game.ServerStorage:FindFirstChild(player.Name.."'s Quests").FindEdgar.Value = 1
	wait(3)
	textLabel.Parent:Destroy()	
end)

yes this is a server script inside a PlayerGui get over it

2 answers

✓ Accepted answer

You can not store a refference to a value of an instance in a variable. That is why your value is not changing, you are essentially creating a "copy" that is not getting applied to the original instance as you intend.

You would directly need to change the instance's value:

local textLabel = script.Parent.NPCText
local text = script.Parent.Words.Value
local length = string.len(text)
local Option1 = textLabel.Option1
local Option2 = textLabel.Option2
local stringvalue = "Sherman"
local player = textLabel.Parent.Parent.Parent
for stop = 1, length do
    wait(0.1)
    textLabel.Text = string.sub(text, 1, stop)
    Option1.Visible = true
    Option2.Visible = true
end

script.Parent.Words.Changed:Connect(function()
    for no = 1, length do
        wait(.1)
        textLabel.Text = string.sub(text, 1, no)
    end
end)

Option1.MouseButton1Click:Connect(function()
    -- text = "Oh Brilliant! Please Hand Him Over!"
    script.Parent.Words.Value = "Oh Brilliant! Please Hand Him Over!";
    Option1.Visible = false
    Option2.Visible = false
    wait(2)
    textLabel.Parent:Destroy()
end)

Option2.MouseButton1Click:Connect(function()
    Option1.Visible = false
    Option2.Visible = false
    text = "Ah I See, Well Would You Please Search For Him For Me?"
    game.ReplicatedStorage.QuestStatus:FireClient(player,stringvalue)
    game.ServerStorage:FindFirstChild(player.Name.."'s Quests").FindEdgar.Value = 1
    wait(3)
    textLabel.Parent:Destroy()  
end)

If you have any more questions, feel free to ask!

1 comment

0

thank you both for answering i always end up with the dumbest issues with the simplest answers

The variable text is not a reference-type, it's a value-type. What this means is that changing won't affect the Text property of Words. In order to change it, you must instead do script.Parent.Words.Text = "Oh Brilliant! Please Hand Him Over!". Ideally you'd also save the text instance Words in a local variable for less indexing.

1 comment

0

why thank you good sir

This discussion is preserved as it was. New answers, comments, and votes are closed.