Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why doesn't this datastore work?

The script is supposed to keep the players health inbetween two places (but are still in the same "universe")!

here is the script

local healthStore = game:GetService("DataStoreService"):GetDataStore("healthStore")
game.Players.PlayerRemoving:connect(function(player)
player:UpdateAsync(player.Name.." saved health", player.Character.Humanoid.Health)
end)

and

local healthStore = game:GetService("DataStoreService"):GetDataStore("healthStore")

game.Players.PlayerAdded:connect(function(player)
player.Character.Humanoid.Health = healthStore:GetAsync(player.Name.." saved health") --sets the Humanoid's health to the saved number, which is the health when the player left the previous Place
end)

this is not my script, I got it from somebody else that helped me!

4 comments

0

NEVER use player.Name use player.userId

0

Also your gonna need OrderedDatastore to get the key,value.

0

K, I switched it on both, testing now

0
  1. What is OrderedDatastore, and how do you use it 2) I am getting an output after making your changes, the output is Workspace.HealthStore recieve:4: attempt to index field 'Character' (a nil value)

1 answer

First Universe:

local healthStore = game:GetService("DataStoreService"):GetDataStore("healthStore")
game.Players.PlayerRemoving:connect(function(player)
player:SetAsync(tostring(player.userId).." saved health", player.Character.Humanoid.Health)
end)

Second Universe:

local healthStore = game:GetService("DataStoreService"):GetDataStore("healthStore")
game.Players.PlayerAdded:connect(function(player)
player.CharacterAdded:connect(function(c)
c.Humanoid.Health = healthStore:GetAsync(tostring(player.userId).." saved health")
end)
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.