Before touching, the value is equal to nothing.
For the points where the bloxy cola factories are located, I made a script with a loop that should check the value of the point and if there is someone’s nickname in the value, the factory should give me a bloxy cola.
while true do
if script.Parent.Player.Value ~= nil then
print("farm")
local Players = game:GetService("Players")
local ownername = script.Parent.Player.Value
local owner = Players:FindFirstChild(ownername)
owner.leaderstats.Bloxy = owner.leaderstats.Bloxy + 1
wait(5)
end
end
For some reason, nothing works, even the print does not give out anything. Thanks in advance.
When using a “While loop”, you must use a wait(). Since you have a wait() within an If Statement, it will only fire when the values are met for the If Statement. Try this…
while true do
if script.Parent.Player.Value ~= nil then
print("farm")
local Players = game:GetService("Players")
local ownername = script.Parent.Player.Value
local owner = Players:FindFirstChild(ownername)
owner.leaderstats.Bloxy = owner.leaderstats.Bloxy + 1
wait(5)
end
wait()
end
You could also just use a GetPropertyChangedSignal function. Simply just replace “while true do” with “script.Parent.Player:GetPropertyChangedSignal(“Value”):Connect(function()” and you don’t even need the wait().
hahahaha, I wanted to sleep when I was writing this script, and today, with a fresh head, I realized that I forgot to specify .Value in line 9 and also incorrectly specified the path to the currency, I also changed nil to " " and everything worked.
while true do
if script.Parent.Player.Value ~= "" then
print("farm")
local Players = game:GetService("Players")
local ownername = script.Parent.Player.Value
local owner = Players:FindFirstChild(ownername)
owner.leaderstats.Bloxys.Value = owner.leaderstats.Bloxys.Value + 1
wait(5)
end
wait()
end
I still recommend using GetPropertyChangedSignal, as using too many while true loops can start to lag your game. It should become a common practice to use alternatives whenever possible. Other than that, good job on finding the error! I can’t tell you how many times I’ve tried to change a Value without typing “.Value”…