So basically, I made a short project in which a player's JumpPower is increased per click, here are the two scripts:
local datastore = game:GetService("DataStoreService")
local powerStore = datastore:GetDataStore("powerStore")
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder", player)
leaderstats.Name = "leaderstats"
local power = Instance.new("IntValue", leaderstats)
power.Name = "Power"
local savedata
local s, f = pcall(function()
savedata = powerStore:GetAsync(player.UserId)
end)
if s then
power.Value = savedata
print("data successfully loaded")
else
print("data not loaded")
end
player.CharacterAdded:Connect(function(character)
character.Humanoid.JumpHeight = power.Value
end)
end)
game.Players.PlayerRemoving:Connect(function(player)
local s, f = pcall(function()
powerStore:SetAsync(player.UserId, player.leaderstats.Power.Value)
end)
if s then
print("data successfully saved")
else
print("data not saved")
end
end)
^ thats the datastore
and this is the GUI:
local button = script.Parent
button.MouseButton1Click:Connect(function()
game.Players.LocalPlayer.leaderstats.Power.Value += 1
game.Players.LocalPlayer.Character.Humanoid.JumpHeight = game.Players.LocalPlayer.leaderstats.Power.Value
end)
When I go in the game, and use F9 to change the value of the power, the datastores works just fine and saves the value, however when I use the button to increase it, then it doesn't save/load anything.
