I used to script games a lot, just getting back into it now.
I am making a simple script that changes a value by adding 1 to it every second. For some reason it won’t work at all. Here is the script:
print("test")
repeat wait() until game:IsLoaded()
print("test")
wait(1)
print("test")
game.Players.PlayerAdded:Connect(function(player)
print("test")
while wait(1) do
print("test")
player.leaderstats.Power.Value = player.leaderstats.Power.Value + 1 + player.leaderstats.Rebirths.Value
print("test")
end
print("test")
end)
print("test")
game:IsLoaded() only works on the client. playerAdded only works on the server. The game is already loaded on the server side, before any scripts run, so remove that.
print("1")
--repeat wait() until game:IsLoaded() --Doesn't work on the server
print("2")
--wait(1) --Player may join before this wait can finish, event wont fire
print("3")
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder") --Leaderstats exist yet?
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local power = Instance.new("IntValue")
power.Name = "Power"
power.Parent = leaderstats
local rebirths = Instance.new("IntValue")
rebirths.Name = "Rebirths"
rebirths.Parent = leaderstats
print("4")
while wait(1) do
print("5")
power.Value += 1 + rebirths.Value --Using +- increments
print("6")
end
print("7")
end)
print("8")
print("test")
game.Players.PlayerAdded:Connect(function(player)
print("test")
while wait(1) do
print("test")
player.leaderstats.Power.Value += 1 + player.leaderstats.Rebirths.Value -- Use += it saves characters.
print("test")
end
print("test")
end)
print("test")