Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why doesn't this datastore work?

Asked by 9 years ago

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!

0
NEVER use player.Name use player.userId MessorAdmin 598 — 9y
0
Also your gonna need OrderedDatastore to get the key,value. MessorAdmin 598 — 9y
0
K, I switched it on both, testing now yogipanda123 120 — 9y
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) yogipanda123 120 — 9y

1 answer

Log in to vote
1
Answered by 9 years ago

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)
Ad

Answer this question