Im using that script
local Player = game:GetService("Players").LocalPlayer local Character = Player.Character local Stats = Player:WaitForChild("leaderstats") local Objects = Player.leaderstats.Objects Objects.Value = 0 Objects.Parent = Stats Objects.Name = "Objects" while true do if script.Parent.Parent.Parent.Parent.Character.Humanoid.Health = 0 then Player.Objects.Value == 0 end end
Is a Local script in Starter gui,Anything wrong in the script or its onlt bad placed?
I see 2 errors in your script.
1st one:
if script.Parent.Parent.Parent.Parent.Character.Humanoid.Health = 0 then Player.Objects.Value == 0 end
You used =
when CHECKING if the player's health is 0 and ==
when SETTING the value of Objects to 0.
=
is used to SET a value and ==
is used to CHECK if a value is equal to another value.
2nd one:
Don't use LocalScripts to save things. Use a Script in ServerScriptStorage instead:
local DataStoreService = game:GetService('DataStoreService') local DataStore = DataStoreService:GetDataStore('SaveSystem') -- you can name SaveSystem something else while wait(1) do -- that way it will check every second game.Players.PlayerAdded:Connect(function(player) local leaderstats = Instance.new('Folder', player) leaderstats.Name = "leaderstats" local Objects = Instance.new("IntValue", leaderstats) Objects.Value = DataStore:GetAsync(player.UserId) or 0 -- it will use the value from the player's data or 0 if joined the first time DataStore:SetAsync(player.UserId, money.Value) Objects.Changed:Connect(function() DataStore:SetAsync(player.UserId, Objects.Value) -- that way it will save Objects whenever it is changed end) end) if player.Character.Humanoid.Health == 0 then Objects.Value = 0 end end
You can use Died event for your script. For example:
local Player = game:GetService("Players").LocalPlayer Player.Character.Humanoid.Died:Connect(function() --your code end)