That error looks like its from using the datastore in studio, so not really related to your cash display gui.
It is if the leaderstats for the player gets changed based off of the datastore script
Yes you are correct about the scriptservice. One of the scripts he had though in his first post would not have worked.
Okay i turned the api access on. xD Didnt realize that
This Gui Script from your Original post will work, you just have to make sure the script that makes the change is working properly. If the datastore script is not the script that changes the value, then the issue lies elsewhere.
local Cash = script.Parent.Parent.Parent.Parent.leaderstats.Cash
Cash.Changed:Connect(function()
script.Parent.Text = "Cash: $"..Cash.Value
end)
Wait isnt somenthing wrong in the leaderstats?
local ds = game:GetService("DataStoreService"):GetDataStore("--Cash01")
game.Players.PlayerAdded:Connect(function(player)
local key = "cash-"..player.userId
local folder = Instance.new("Folder",player)
folder.Name = "leaderstats" -- Must be lowercase
local currency = Instance.new("IntValue",folder)
currency.Name = "Cash"
currency.Value = 0
local save = ds:GetAsync(key)
if save then
currency.Value = save
end
currency.Changed:Connect(function()
ds:SetAsync(key,currency.Value)
end)
end)
Also dont parent the folder right on the Instance.new(), its a bad thing to do when you didnt even set the things at it.
It shouldve been
local folder = Instance.new("Folder")
folder.Name = "leaderstats"
folder.Parent = player
-- Do the same to the currency.
And another thing is that the datastore has a high chance to fail in that way, saving everytime a thing changes is bad because chance of throttling and there are no pcalls on there.
I guess i just failed everything in the script.
I tried
game.Players.PlayerAdded:Connect(function(player)
local leaderstas = Instance.new("Folder", player)
leaderstas.Name = "leaderstats"
local cash = Instance.new("IntValue", leaderstas)
cash.Name = "Cash"
end)
For the leaderstats
And for the LocalScript in the Gui
local player = game.Players.LocalPlayer
local stats = player:WaitForChild("leaderstats")
local cash = stats:WaitForChild("Cash")
script.Parent.Text = "Cash: "..cash.Value
while wait() do
script.Parent.Text = "Cash: "..cash.Value
end
And still not working
I define the parent right away on the instance line, its not bad practice nor does it not work. Dont downvote this practice as it saves time and makes the scripting much easier.
It doesn’t make it not work, its just a bad practice that should be avoided.
I guess i just failed everything in the script.
Failure is part of improvement.
I define the parent right away on the instance line, its not bad practice nor does it not work. Dont downvote this practice as it saves time and makes the scripting much easier.
Bad, bad advice.
Here’s a quick comparison you can do in your own commandline. Instantiating a part, setting its position, then destroying it about 100 times.
local pt = tick() for i = 1, 100 do local a = Instance.new("Part", workspace) a.Position = Vector3.new(0, 10, 0) a:Destroy() end local pe = tick() local ft = tick() for i = 1, 100 do local a = Instance.new("Part") a.Position = Vector3.new(0, 10, 0) a.Parent = workspace a:Destroy() end local fe = tick() print(pe-pt) print(fe-ft)
about 10 times slower w/ parent argument if i read properly
I tried [code]
For the actual issue, try using print() inside the wait() loop you wrote to see if it runs at all as well as some other code parts to verify if the game doesn’t stop at an earlier point
while wait() do -- this one
script.Parent.Text = "Cash: "..cash.Value
end
Yes, as this may be true, the only reason you would need to set the parent after setting all the other values is to already have the name of things ready, this doesnt effect thing such as folders or int values at all. As it will only really effect things like parts where they will have the color before going into workspace.
Thats wrong, you should read that post again.
It consumes more memory to change properties after parenting a thing than changing them before parenting, this rule applies to all instances as I understood since they have default things.
In this case, the default name is Folder and you renamed it to leaderstats which made you use more memory when you could simply set it before putting it into the game so the game doesnt need to use more memory than needed.
Also it doesnt hurt to add more a line to your code right?
Alright, I must’ve skipped over that part of the explanation thanks
At this point im confused not just little bit, im completely confused. Its just maybe because i know only the basics of lua. But im not really sure which of them i should use to make it work, guess my game will just be complete mess.
The only error in your code is trying to check server script storage.
Here is what you shouldve did:
local cash = game.Players.LocalPlayer.leaderstats.Cash
cash.Changed:Connect(function()
script.Parent.Text = "Cash: $"..cash.Value
end)
I just found out maybe i have too much leaderstats out there