Hello so I made a randomised height script with a datastore and im having issues saving the players randomised height. I'm trying to make it so when the player leaves the game the height they had gets saved so if they rejoin they would still have that height. What am I doing wrong?
Heightsave = game:GetService("DataStoreService"):GetDataStore("HS") game.Players.PlayerAdded:Connect(function(plr) wait() local Heights = {2, 4, 8, 16} local randomHeight = Heights[math.random(1,#Heights)] repeat wait(.2) until plr.Character local hum = plr.Character:WaitForChild("Humanoid") local Height = hum:WaitForChild("BodyHeightScale") local key = plr.UserId local savedHeight = Heightsave:GetAsync(key) if savedHeight then --loads player that already joined game height Height.Value = savedHeight[2] else -- player never joined so sets there height Height.Value = randomHeight end end) game.Players.PlayerRemoving:Connect(function(plr) local key = plr.UserId repeat wait(.2) until plr.Character local hum = plr.Character:WaitForChild("Humanoid") local Height = hum:WaitForChild("BodyHeightScale") local toSaveHeight = {plr.Height.Value} Heightsave:SetASync(key, toSaveHeight) end)
Unless I'm missing something, this:
Height.Value = savedHeight[2]
and this:
local toSaveHeight = {plr.Height.Value}
don't seem compatible. You're saving an array with only one element, but trying to access an element with index 2 when you load the data.
The second issue is that here:
local Height = hum:WaitForChild("BodyHeightScale") local toSaveHeight = {plr.Height.Value}
You have a local variable called Height
, but you're trying to save plr.Height.Value
, which should just be Height.Value