It doesnt add 1 when clicked

Im trying to make a dialog so everytime i press the button it adds 1 to a value but that value doesnt seem to change I know its a pretty dumb question but I cant find anywhere what I did wrong and I its been a while since I worked on a game.

it does work for the first “if” when the value == 1 but when it goes to 2 it just repeats 1

local TextLabel = script.Parent:WaitForChild("Gradient"):WaitForChild("TextHolder")
local Sound = TextLabel.Typewriter
local Button = TextLabel.Parent.Button
local Replace = TextLabel.Parent.Image
local Clicked = 0
wait(1)

local function typewrite(object,text,length)
	for i = 1,#text, 1 do
		Sound:Play()
		object.Text = string.sub(text, 1, i)
		wait(length)
	end
end
if Button.MouseButton1Up then
	Clicked = Clicked +1
end
Button.MouseButton1Up:Connect(function()
	if Clicked == 1 then
		Button.Visible = false
		Replace.Visible = true
		typewrite(TextLabel, "it looks like the door is locked", 0.05)
		Button.Visible = true
		Replace.Visible = false
	elseif Clicked == 2 then
		Button.Visible = false
		Replace.Visible = true
		typewrite(TextLabel, "maybe there is a key somewhere here", 0.05)
		Button.Visible = true
		Replace.Visible = false
	elseif Clicked == 3 then
		script.Parent:Destroy()
	end
	
end)
local TextLabel = script.Parent:WaitForChild("Gradient"):WaitForChild("TextHolder")
local Sound = TextLabel.Typewriter
local Button = TextLabel.Parent.Button
local Replace = TextLabel.Parent.Image
local Clicked = 0
wait(1)

local function typewrite(object,text,length)
	for i = 1,#text, 1 do
		Sound:Play()
		object.Text = string.sub(text, 1, i)
		wait(length)
	end
end

	
Button.MouseButton1Up:Connect(function()
	if Clicked == 0 then
		Button.Visible = false
		Replace.Visible = true
		Clicked = Clicked + 1
		typewrite(TextLabel, "it looks like the door is locked", 0.05)
		Button.Visible = true
		Replace.Visible = false
		
	elseif Clicked == 1 then
		Button.Visible = false
		Replace.Visible = true
		Clicked = Clicked + 1
		typewrite(TextLabel, "maybe there is a key somewhere here", 0.05)
		Button.Visible = true
		Replace.Visible = false
	elseif Clicked == 2 then
		script.Parent:Destroy()
	end
	
end)

this is the new script i think the issue was the fact that the changed number stayed in the “if” kinda like a function.

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