Changed Value Script only Works if Player Rejoins the game?

Hello I ran across a problem with this Changed function script. Once you reach the necessary amount of points a UI is supposed to pop up but it does not pop up. It only pops up if you join the game. Does anyone know why? Any help is appreciated.

popPoints:GetPropertyChangedSignal("Value"):Connect(function()
	task.wait(0.001)

	if debounce == false then
		debounce = true
		if popPoints.Value >= requiredXP.Value then	
			if Player.tutorialStats.didTutorial.Value == "true" then

		
				purchaseUI:TweenPosition(UDim2.new(0.358, 0,0.738, 0))
1 Like

Could you show us the entire function?
Also, what is the task.wait(0.001) used for?

Here is the full function

popPoints:GetPropertyChangedSignal("Value"):Connect(function()
	wait(0.001)

	if debounce == false then
		debounce = true
		if popPoints.Value >= requiredXP.Value then	
			if Player.tutorialStats.didTutorial.Value == "true" then

				--//Functions

				purchaseUI:TweenPosition(UDim2.new(0.358, 0,0.738, 0))

				--// Open, Purchase, Close Function
				
				local function getLocation(WorldTo)
					
					local fVar = ""
					local Data = {
						
						["1"] = Arrowsw["Winter Forest"].Arrows.ArrowDirection,
						["2"] = Arrowsw["Mushroom Forest"].Arrows.ArrowDirection,
						
					}
					
					if WorldTo == "1" then
						fVar = Data["1"]
					end 
					
					if WorldTo == "2" then
						fVar = Data["2"]
					end
					
					return(fVar)
					
				end

				local function getData(Worlds)

					local fVar = ""
					local Data = {

						["1"] = "2500",
						["2"] = "13500",

					}

					if Worlds == "1" then
						fVar = Data["1"]
					end

					if Worlds == "2" then
						fVar = Data["2"]
					end

					return(fVar)
				end
				
				local function pathToPart(Arrows, a0, part) 
					local a1 = part:FindFirstChildOfClass("Attachment")
					if a1 then
						Arrows.Attachment0 = a0
						Arrows.Attachment1 = a1
					else
						warn("No attachment was inserted into "..part:GetFullName())
					end
				end

				local function closeFunction()

					purchaseUI:TweenPosition(UDim2.new(0.358, 0,1.5, 0))
					debounce = false

				end
				
				local function boughtMap()
					
					-- Points
					
					local PopsTaken = (getData(Player:WaitForChild("MapWorld").Value))
					ReplicatedaStorage.popsSpent.Spent:FireServer(PopsTaken,popStarters,requiredXP,popPoints)
					--popStarters.Value = popStarters.Value + 1
					--requiredXP.Value = popStarters.Value * 1250
					
					-- Map Variables
					
					--Player.worldStats.unlockedMushroom.Value = "true" 
					--Player.worldStats.boughtMushroom.Value = "true"
					
					-- GUI
					purchaseUI:TweenPosition(UDim2.new(0.358, 0,1.5, 0))
					script.Parent.Directions:TweenPosition(UDim2.new(0.359, 0,0.741, 0))
					
					-- Arrows 
					
					local root = Character:WaitForChild("HumanoidRootPart")
					local a0 = root:WaitForChild("RootRigAttachment")
					pathToPart(Arrows, a0, getLocation(Player:WaitForChild("MapWorld").Value))
					Arrows.Parent = root
					
					-- Confetti
					
					local confetti = script.Parent.ConfettiFrame
					confetti.Confetti.Disabled = false
					task.wait(4)
					confetti.Confetti.Disabled = true

				end
				
				
				local Destroyed = game.Workspace
				local Winter = Destroyed.ArrowDestroyed2
				local Mushroom = Destroyed.ArrowDestroyed3
				
				local db1 = false
				Winter.Touched:Connect(function()
					
					if db1 == false then
						db1 = true
					local Arrow = Character:WaitForChild("HumanoidRootPart").ArrowToFindPart
					Arrow.Enabled = false
						task.wait(3)
						script.Parent.Directions:TweenPosition(UDim2.new(0.359, 0,1.5, 0))
						Arrow:Destroy()
						
					end
				end)
				
				--Mushroom.Touched:Connect(function()
					--local Arrow = Character:WaitForChild("HumanoidRootPart").ArrowToFindPart
					--Arrow.Enabled = false
					--task.wait(3)
					--Arrow:Destroy()

				--end)
				
				--// Connect Functions

				purchaseUI.ConfirmUI.Buy.MouseButton1Click:Connect(boughtMap)
				purchaseUI.ConfirmUI.Exit.MouseButton1Click:Connect(closeFunction)
				

			end

		end

	end
end)

I’m not sure, someone fixed the script a while ago and put task.wait Im not sure what it does but I believe it’s like wait()

The variable called “Player” is this provided by Players:PlayerAdded?

I also noticed this:
if Player.tutorialStats.didTutorial.Value == "true" then
Doing the following would be sufficient, assuming the didTutorial value returns a boolean:
if Player:tutorialStats.didTutorial.Value then

I’m using LocalPlayer for the script since it is a Local Script. Also i changed the line to if Player:tutorialStats.didTutorial.Value then

The script still won’t work. It only works if I rejoin the game

Once the debounce was turned to true (the 1st time it ran past it) it never gets past that part in the script again. So the only time that would work out is if Payer.tutorialStats.didTutorial.Value == “true” and it was the 1st time it was ever called.

You want to move your debounce = true under the Payer.tutorialStats.didTutorial.Value == “true” line.

As is you’re not using debouce as a “debouce” you’re using it as a flag. Then wrighting it as a debounce. This will run past these lines once then never get past the if debounce == false

The debounce gets set to false again after calling the closeFunction

Try using the Debugging Tools provided by Roblox to debug your code, and see where exactly it halts. If you don’t know how to, you should probably start experimenting with it! If you still have troubles, add a few print(1) lines in your code and gradually increase the number to see up to whatever point it stops.

This is a very messy way of debugging and shouldn’t be common practice, but without knowledge over the Debugging Tools it’ll have to do!

Wow, he posted a 2nd complete script in that time. Grrr
Why is there functions within functions all raw like that.

I’m not sure, it definitely isn’t clean, but that shouldn’t be the reason the script doesn’t work.

1 Like

I’m not that good in organizing scripts :joy:

This worked btw I put the debounce under the If statement

I knew that was why it was doing what you said from what you said. … But, you should pull every single one of them function out of that other function and place them above it and get used to using them that way. In the long run you will save yourself major debugging. As is every time that 1st function is being called it is actually redefining the functions within it. A function only needs to be defined once.

1 Like