Hello so, I am trying to make a game on ROBLOX, pretty simple were each second you get +1 jump power, now I got the jump power thingy up and running, but I want to do so it saves when a player leaves and joins, so far I found this code on the internet, but nothing worked, here is the code.
local DataStores = game:GetService("DataStoreService") local FirstDataStore = DataStore:GetDataStore("JumpPowerStorage")
game.Players.PlayerAdded:connect(function(player) wait(0.1) player.Character.Humanoid.JumpPower = FirstDataStore:GetAsync(player.UserId) or 0 FirstDataStore:SetAsync(player.UserId, player.Character.Humanoid.JumpPower) player.Character.Humanoid.Changed:connect(function() FirstDataStore:SetAsync(player.UserId, player.Character.Humanoid.JumpPower) end) end) game.Players.PlayerRemoving:connect(function(player) FirstDataStore:SetAsync(player.UserId, player.Character.Humanoid.JumpPower) end)
please help me fix it, thanks.
Inside the variable FirstDataStore
, you use "DataStore", and not the actual variable "DataStores". Replace DataStore with DataStores and you should be good to go.
local DataStores = game:GetService("DataStoreService") local FirstDataStore = DataStores:GetDataStore("JumpPowerStorage") game.Players.PlayerAdded:connect(function(player) wait(0.1) player.Character.Humanoid.JumpPower = FirstDataStore:GetAsync(player.UserId) or 0 FirstDataStore:SetAsync(player.UserId, player.Character.Humanoid.JumpPower) player.Character.Humanoid.Changed:connect(function() FirstDataStore:SetAsync(player.UserId, player.Character.Humanoid.JumpPower) end) end) game.Players.PlayerRemoving:connect(function(player) FirstDataStore:SetAsync(player.UserId, player.Character.Humanoid.JumpPower) end)
Try this
local DataStores = game:GetService("DataStoreService") local FirstDataStore = DataStores:GetDataStore("JumpPowerStorage") game.Players.PlayerAdded:Connect(function(player) wait(0.1) player.CharacterAdded:Connect(function(character) local humanoid = character:WaitForChild("Humanoid") humanoid.JumpPower = FirstDataStore:GetAsync(player.UserId) or 0 humanoid.Changed:Connect(function() FirstDataStore:SetAsync(player.UserId, humanoid.JumpPower) end) end) end) game.Players.PlayerRemoving:Connect(function(player) if player.Character then local humanoid = player.Character:WaitForChild("Humanoid") FirstDataStore:SetAsync(player.UserId, humanoid.JumpPower) end end)