Hi! I’ve been making a game where the jump power goes up by one every second, it worked initially but now it is no longer working and I have no idea why, heres my code:
local DataStoreService = game:GetService("DataStoreService")
local myDataStore = DataStoreService:GetDataStore("myDataStore")
local function updateJump(Humanoid, Jump)
Humanoid.UseJumpPower = true
Humanoid.JumpPower = Jump
end
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local Jump = Instance.new("IntValue")
Jump.Name = "Jump Power"
Jump.Parent = leaderstats
local Win = Instance.new("IntValue")
Win.Name = "Wins"
Win.Parent = leaderstats
local playerUserId = "Player"..player.UserId
local data
local success, errormessage = pcall(function()
data = myDataStore:GetAsync(playerUserId)
end)
if success then
Jump.Value = data -- loads jump power
Win.Value = data -- loads wins
end
player.CharacterAdded:Connect(function(Character)
while wait(1) do
player.leaderstats.Jump.Value += 1 -- makes the jump power go up every secodn
updateJump(Character.Humanoid, Jump.Value)
end
end)
end)
game.Players.PlayerRemoving:Connect(function(player)
local playerUserId = "Player"..player.UserId
local data = player.leaderstats.Jump.Value
local data = player.leaderstats.Win.Value
myDataStore:SetAsync(playerUserId, data) --saves the persons data when they leave
end)
The error message is:
Jump is not a valid member of Folder "Players.AlekGamer_TV.leaderstats" - Server - Main:44
The issue is that you created the object with the name of “Jump Power” instead of Jump, so no object called Jump exists!
To correct this issue, have it as
local data = player.leaderstats["Jump Power"].Value
Also, your jump power isn’t going to save either way. Although you initially get the value and save it to data, the data variable is redefined the next line as the amount of wins they have. To save the 2 variables will be a bit more complicated, involving saving it as json instead. I’ll write out the code instead of trying to explain anything, but if you get confused on anything let me know!
local DataStoreService = game:GetService("DataStoreService")
local myDataStore = DataStoreService:GetDataStore("myDataStore")
local HTTPService = game:GetService("HttpService")
local function updateJump(Humanoid, Jump)
Humanoid.UseJumpPower = true
Humanoid.JumpPower = Jump
end
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local Jump = Instance.new("IntValue")
Jump.Name = "Jump Power"
Jump.Parent = leaderstats
local Win = Instance.new("IntValue")
Win.Name = "Wins"
Win.Parent = leaderstats
local playerUserId = "Player"..player.UserId
local dataRaw
local success, errormessage = pcall(function()
dataRaw = myDataStore:GetAsync(playerUserId)
end)
if success then
local data = HTTPService:JSONDecode(dataRaw)
Jump.Value = data["Jump"] -- loads jump power
Win.Value = data["Win"] -- loads wins
end
player.CharacterAdded:Connect(function(Character)
while wait(1) do
player.leaderstats.Jump.Value += 1 -- makes the jump power go up every secodn
updateJump(Character.Humanoid, Jump.Value)
end
end)
end)
game.Players.PlayerRemoving:Connect(function(player)
local playerUserId = "Player"..player.UserId
local data = {
["Jump"] = player.leaderstats["Jump Power"].Value,
["Win"] = player.leaderstats.Wins.Value
}
myDataStore:SetAsync(playerUserId, HTTPService:JSONEncode(data)) --saves the persons data when they leave
end)