So I’m trying to make a Roblox game at 1 am because who doesn’t and i ran into a small problem: I have a variable that wont update in my server script even if i can see it being updated in the explorer and leaderstats.
My cultivation toggle script (local script under the text button):
local button = script.Parent
local cultivating = game.Players.LocalPlayer.leaderstats.Cultivating
button.MouseButton1Click:Connect(function()
if cultivating.Value == false then
cultivating.Value = true
button.Text = "Stop Cultivating"
else
cultivating.Value = false
button.Text = "Start Cultivating"
end
end)
My leaderstats script (server script under serverscriptservice):
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local qi = Instance.new("IntValue")
qi.Name = "Qi"
qi.Value = 0
qi.Parent = leaderstats
local cultivating = Instance.new("BoolValue")
cultivating.Name = "Cultivating"
cultivating.Value = true
cultivating.Parent = leaderstats
end)
My cultivation script (server script under serverscriptservice):
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = player:WaitForChild("leaderstats")
local qi = leaderstats:WaitForChild("Qi")
local cultivating = leaderstats:WaitForChild("Cultivating")
while true do
if cultivating.Value == true then
qi.Value += 1
end
wait(0.5)
end
end)
I know this probably a stupid question and before you run to the downvote button take in mind that it is currently 2:03 in the morning and I have asked both chatgpt and claude ai to help me and they have both failed. Basically the variable “cultivating” is getting updated by the local script which works but doesn’t get updated inside the cultivation script.
I was expecting this to give me 1 qi every 0.5 seconds if I’m cultivating.
I tried using AI to help me (time wasted), tried debugging with a bunch of print statements and got to the conclusion that it is indeed the variable not updating inside the script. I have even tried declaring the variable inside the loop without any success.
P5yui is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.