Boolen says that is ture tho it is false? moudle script

In my NPC quest system, I have a function that shows/hides a UI with a tween animation. The function sets WorkingTween to true when the tween starts and false when it finishes.

However, at some point, WorkingTween turns false as expected, but when the function is called again, it still thinks WorkingTween is true, preventing the tween from running.



local sound = script:WaitForChild("استاذ فرقان صوت")
local Tweenservice = game:GetService("TweenService")
local continueBool = false
local tweeninfos = {
	["ShowUpTween"] = TweenInfo.new(0.5,Enum.EasingStyle.Exponential,Enum.EasingDirection.Out),
	["HideUpTween"] = TweenInfo.new(0.4,Enum.EasingStyle.Exponential,Enum.EasingDirection.In)

}
local WorkingTween = false
local module = {

	ShowHideUpQuest = function(Ui:ScreenGui,ShowOrHide:string)
		if ShowOrHide == "show"  and not WorkingTween then
			local Frame:Frame = Ui:FindFirstChild("Frame")
			if Frame then
				local targetPositioin = Frame.Position
				Frame.Position = targetPositioin + UDim2.new(0,0,1,0)
				Ui.Enabled = true
				local Tween = Tweenservice:Create(Frame,tweeninfos["ShowUpTween"],{Position = targetPositioin})
				WorkingTween = true

				Tween:Play()
				Tween.Completed:Wait()
				WorkingTween = false
				print("updated workning tween to false")


				
			end
		elseif ShowOrHide == "hide" and not WorkingTween then
			local Frame:Frame = Ui:FindFirstChild("Frame")
			if Frame then
				WorkingTween = true

				local FrameOrignallPosition = Frame.Position
				local targetPose = Frame.Position + UDim2.new(0,0,1,0)
				local Tween = Tweenservice:Create(Frame,tweeninfos["ShowUpTween"],{Position = targetPose})
				Tween.Completed:Wait()
				Ui.Enabled = false
				Frame.Position = FrameOrignallPosition
				WorkingTween = false


			end
		
		else
			print("error couldn't Know what is ,",ShowOrHide,"it might be cuz there is tween ",WorkingTween)
		end
	end,
	

here a video to make it clear

ty <3

Looking at the module script, I don’t see anything wrong with it. You might want to show the Local Script calling the module and using it.

Also I would suggest you place WorkingTween = true at the top

if Frame then
	WorkingTween = true -- moved to top
	local targetPositioin = Frame.Position
	Frame.Position = targetPositioin + UDim2.new(0,0,1,0)
1 Like

Instead of making a separate variable and updating it to check when a tween is active

Make the active tween a variable itself which then you could connect a cleanFn to when it finished that sets it to nil and stuff

To check when a tween is playing you just check if the tween exists

1 Like

Here is the full moudel script it soo weird

local sound = script:WaitForChild("استاذ فرقان صوت")
local Tweenservice = game:GetService("TweenService")
local tweeninfo = TweenInfo.new(0.5,Enum.EasingStyle.Back,Enum.EasingDirection.In)
local continueBool = false
local tweeninfos = {
	["ShowUpTween"] = TweenInfo.new(0.5,Enum.EasingStyle.Exponential,Enum.EasingDirection.Out),
	["HideUpTween"] = TweenInfo.new(0.4,Enum.EasingStyle.Exponential,Enum.EasingDirection.In)

}
local WorkingTween = false
local module = {
	CharacterSounds = 11,
	SplitTextFunction = function(Text:string,voiceid,TextLabe:TextLabel)
	
		local SplitText = Text:split("")
		local ReText = ""
		for _,Letter in ipairs(SplitText) do
			if continueBool then
				break
			end
			sound:Play()
			ReText = ReText..Letter
			TextLabe.Text = ReText
			task.wait(0.07)
			sound:stop()

		end
		
	end,
	ShowHideUpQuest = function(Ui:ScreenGui,ShowOrHide:string)
		if ShowOrHide == "show"  and not WorkingTween then
			local Frame:Frame = Ui:FindFirstChild("Frame")
			if Frame then
				local targetPositioin = Frame.Position
				Frame.Position = targetPositioin + UDim2.new(0,0,1,0)
				Ui.Enabled = true
				local Tween = Tweenservice:Create(Frame,tweeninfos["ShowUpTween"],{Position = targetPositioin})
				WorkingTween = true

				Tween:Play()
				Tween.Completed:Wait()
				WorkingTween = false
				print("updated workning tween to false")


				
			end
		elseif ShowOrHide == "hide" and not WorkingTween then
			local Frame:Frame = Ui:FindFirstChild("Frame")
			if Frame then
				WorkingTween = true

				local FrameOrignallPosition = Frame.Position
				local targetPose = Frame.Position + UDim2.new(0,0,1,0)
				local Tween = Tweenservice:Create(Frame,tweeninfos["ShowUpTween"],{Position = targetPose})
				Tween.Completed:Wait()
				Ui.Enabled = false
				Frame.Position = FrameOrignallPosition
				WorkingTween = false


			end
		
		else
			print("error couldn't Know what is ,",ShowOrHide,"it might be cuz there is tween ",WorkingTween)
		end
	end,
	
	
	Characters = {
		["Fox"] = {
			QuestTalkLines = {"Hello there would u like to help me please?","Well there is boxes over there can u bring them to me ?","Testoo:"},
			FinshQuestLine = "Thank here a reward for u",
			WaitingForQuestToFinsh = "soo are u bringing those boxes or not?",
			Decline_Line = "Whatever u are too weak anyway to do it "
		},
		["Leeyo"] = {
			QuestTalkLines = {"Ya dwag how u doin","i only want food 😭","HAHAHAHAH"},
			FinshQuestLine = "Thank here a reward for u",
			WaitingForQuestToFinsh = "soo are u bringing those boxes or not?",
			Decline_Line = "u wont help i hopeless old man >:) "

		},
		["mxxitixx"] = {
			QuestTalkLines = {"Sub my name is mobse","well can u talk to turkish for me?","so do we have a deal"},
			FinshQuestLine = "Thank here a reward for u",
			WaitingForQuestToFinsh = "are you going to talk to him?",
			Decline_Line = "I guess i am going to talk to him "

		},
	}
}

function module:SetViewPortFrame(ViewportFrame:ViewportFrame,Character:Model)
		print(ViewportFrame,Character)
		for _,Thing in ViewportFrame:GetChildren() do
			if Thing:IsA("Model") or Thing:IsA("Camera") then
				Thing:Destroy()
			end
		end
		local CharacterClone = Character:Clone()
		CharacterClone:PivotTo(CFrame.new(0,0,0))
		local newCamerea = Instance.new("Camera")
		newCamerea.Parent = ViewportFrame
		newCamerea.CFrame = CFrame.new(-0.151978925, 4.86038303, -2.51316714, -0.996948421, 0.0077367234, -0.0776794329, -0, 0.995076835, 0.0991077423, 0.0780637637, 0.0988053083, -0.992040157)
		ViewportFrame.CurrentCamera = newCamerea
		CharacterClone.Parent = ViewportFrame
end


function module:SetUpQuest(Ui:ScreenGui,Character,Player:Player)
	local CharacterLines = self.Characters
	local CharacterLine = CharacterLines[Character.Name]
	local Frame:Frame = Ui:WaitForChild("Frame")
	local NPCIMAGe = Frame:WaitForChild("NpcImage")

	local NPCLINE = Frame:WaitForChild("NpcLine")
	local continueBtn:TextButton = Frame:WaitForChild("continue")
	local viewPortFrame:ViewportFrame = NPCIMAGe:WaitForChild("ViewportFrame")
	self.ShowHideUpQuest(Ui,"show")
	if Player:FindFirstChild("QUEST").Value == Character.Name.."Quest" then
		if CharacterLine then
			self.SplitTextFunction(CharacterLine["WaitingForQuestToFinsh"],nil,NPCLINE)
			return
		end

	end
	if CharacterLines then

		self:SetViewPortFrame(viewPortFrame,Character)
		continueBtn.MouseButton1Click:Connect(function()
			if continueBtn.Text == "Accept" then
				self.ShowHideUpQuest(Ui,"hide")
				print("hide ui ")

			end
			continueBool = true

		end)
		for _,NormalLine in ipairs(CharacterLine.QuestTalkLines) do
			if _ == #CharacterLine.QuestTalkLines then
				continueBtn.Text = "Accept"
				
			end
			self.SplitTextFunction(NormalLine,nil,NPCLINE,continueBool)
			while not  continueBool  do
				task.wait()
			end
			continueBool = false
		end
		


		local Quest = Player:FindFirstChild("QUEST")
		if Quest then
			Quest.Value = Character.Name.."Quest"
		end
		return true
	end

end
return module

god i am so silly the problem wasnt with the workingtween boolen it was that the hide tween never played :silly:

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