Weird DataStore error

So i was fixing my roulette table then this happened.

image

I didn’t even touch this script. And i know the error comes from this script because if it succeeded, then a gui would apear… but it just broke.

script.Parent.ClickDetector.MouseClick:Connect(function(plr)
	if not script.Parent.Parent.Parent.Parent.DontBet.Value then
		if script.Parent.Parent.Parent:FindFirstChild(plr.Name) == nil then
			local guiOpen = Instance.new("BoolValue")
			guiOpen.Name = plr.Name
			guiOpen.Value = false
			guiOpen.Parent = script.Parent.Parent.Parent
		end
		
		if script.Parent:FindFirstChild(plr.Name) ~= nil then
			plr.leaderstats.G.Value = plr.leaderstats.G.value + script.Parent:FindFirstChild(plr.Name).Bet.Value
			plr.leaderstats.Token.Value = plr.leaderstats.Token.Value + 1
			script.Parent:FindFirstChild(plr.Name):Destroy()
		end
		
		if not script.Parent.Parent.Parent[plr.Name].Value then
			script.Parent.Parent.Parent[plr.Name].Value = true
			
			local gui = game.ServerStorage.BetGui:Clone()
			gui.BNumber.Value = tonumber(script.Parent.Name)
			gui.BColor.Value = script.Parent.SurfaceGui.Frame.BackgroundColor3
			gui.Close.Value = script.Parent.Parent.Parent[plr.Name]
			gui.BetFolderParent.Value = script.Parent
			gui.Parent = plr.PlayerGui
		end
	end
end)

This doesn’t use DataStore in ANY way (that i see).

Can anyone help? I would appreciate it. :grinning:

PS.: It errored out at line 16 ish.

The error on line 16 makes completly no sense. Are you really sure the error is happening in this script? It could be as well something with collaborative editing, if you have collaborative editing on, then check you have commited changes. It’s really weird.

  1. yes 90% sure it’s from this script
  2. team create is off and was off since 2020.12 - ish
  3. and the line 16 ish thing is that it happens somewhere in that if sentance, since it gives back your money (2. if statement)

i should have clarified, sorry

This is the script because it runs fine the first time, then throws this error the second.
And if it ran fine, the gui would apear.

Could you put some prints into the script you think the error comes from? You might be running into multiple issues.

Yes of corse. One moment. {Something here}

image

First run (to the random “34” line)
Fine

Next run
No need to create check
Broke
Gave your money back (intentional, not an error condition)

But the money saves when you leave, and not when changed…
And changing the money value doesn’t use DataStore.
Hmmm

So it broke 2. if statement.

script.Parent.ClickDetector.MouseClick:Connect(function(plr)
	if not script.Parent.Parent.Parent.Parent.DontBet.Value then
		if script.Parent.Parent.Parent:FindFirstChild(plr.Name) == nil then
			local guiOpen = Instance.new("BoolValue")
			guiOpen.Name = plr.Name
			guiOpen.Value = false
			guiOpen.Parent = script.Parent.Parent.Parent
			print("Created GuiCheck")
		end
		
		if script.Parent:FindFirstChild(plr.Name) ~= nil then
			plr.leaderstats.G.Value = plr.leaderstats.G.value + script.Parent:FindFirstChild(plr.Name).Bet.Value
			plr.leaderstats.Token.Value = plr.leaderstats.Token.Value + 1
			script.Parent:FindFirstChild(plr.Name):Destroy()
			print("Gave back your money")
		end
		
		if not script.Parent.Parent.Parent[plr.Name].Value then
			print("Gui creation started")
			script.Parent.Parent.Parent[plr.Name].Value = true
			print("Gui open signal")
			
			local gui = game.ServerStorage.BetGui:Clone()
			print("Gui cloned")
			gui.BNumber.Value = tonumber(script.Parent.Name)
			print("Gui edited")
			gui.BColor.Value = script.Parent.SurfaceGui.Frame.BackgroundColor3
			print("Gui edited")
			gui.Close.Value = script.Parent.Parent.Parent[plr.Name]
			print("Gui edited")
			gui.BetFolderParent.Value = script.Parent
			print("Gui edited")
			gui.Parent = plr.PlayerGui
			print("Gui parented to PlayerGui")
		end
	end
end)

Could you show us the script which is giving back the money? I think the issue will be over there.

image

script.Parent.ClickDetector.MouseClick:Connect(function(plr)
	if not script.Parent.Parent.Parent.Parent.DontBet.Value then
		if script.Parent.Parent.Parent:FindFirstChild(plr.Name) == nil then
			local guiOpen = Instance.new("BoolValue")
			guiOpen.Name = plr.Name
			guiOpen.Value = false
			guiOpen.Parent = script.Parent.Parent.Parent
		end
		
		if script.Parent:FindFirstChild(plr.Name) ~= nil then
			print("Entered statement")
			plr.leaderstats.G.Value = plr.leaderstats.G.value + script.Parent:FindFirstChild(plr.Name).Bet.Value
			print("Gave back Gold")
			plr.leaderstats.Token.Value = plr.leaderstats.Token.Value + 1
			print("Gave back Token")
			script.Parent:FindFirstChild(plr.Name):Destroy()
			print("Deleted check")
			print("Gave back your money")
		end
		
		if not script.Parent.Parent.Parent[plr.Name].Value then
			script.Parent.Parent.Parent[plr.Name].Value = true
			
			local gui = game.ServerStorage.BetGui:Clone()
			gui.BNumber.Value = tonumber(script.Parent.Name)
			gui.BColor.Value = script.Parent.SurfaceGui.Frame.BackgroundColor3
			gui.Close.Value = script.Parent.Parent.Parent[plr.Name]
			gui.BetFolderParent.Value = script.Parent
			gui.Parent = plr.PlayerGui
		end
	end
end)

This is what gives back the money.

  1. if statement

It looks just like some script is saving the money when the Value gets changed. Maybe there is some script that you don’t even know about? I think there might be some script that you don’t know about based on that you are saying that you aren’t saving the money when the Value gets changed, but just when the Player leaves.

You can search for the scripts by using Ctrl + Shift + F and searching for DataStore.

image

Just as i tought, nothing. Could it be that i just… make another script handle the money change? Like with events?

Those scripts i made btw.

I’m starting to run out of ideas. The last thing that I think might be the issue is the script that is used for saving money itself. If the problem is not there as well then I’m sorry, but I won’t be able to help you.

Don’t worry, you helped plenty.
I’ll just remake it or do the thing i asked you last reply.

1 Like

I don’t think that would solve anything, because the error comes probably from somewhere else. You could try to change your money Value manually and see if the error pops up. If it doesn’t then it’s even more weird than I thought it is.

If i spam changes to it, it gives the error!!!
YOU ARE A GOD
:partying_face:

I fixed it. Thank you so much dude. Doing this since 6:20.
Sometimes another perspective does it.

1 Like

Yeah don’t spam and like save stuff to a datastore too quickly or whatever or else you’ll have this happen although seems like you’ve already figured that out, but yeah.