So you have a few issues. A big one being you're not using datastores, if you don't know what those are, they're what saves your player data so when they leave and rejoin, all of their money/health/level doesn't get set to 0. Heres a useful video to learn about datastores: youtube.com/watch?v=DkYupSBUpes
I'm not going to teach you about datastores, but I will tell you how to make the players health increment.
Another small thing is that you're not using variables, which bugs me a little bit.
1. Add a RemoteEvent in ReplicatedStorage
2. Add the script into ServerScriptService
3. Add the local script into StarterPlayer>StarterPlayerScripts
Script in ServerScriptService
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage:WaitForChild("remoteEvent")
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
remoteEvent.OnServerEvent:Connect(function(player, level)
local humanoid = character:WaitForChild("Humanoid")
local moneyPerLevel = 50
local function update()
humanoid.MaxHealth = moneyPerLevel * level
end
update()
print("Players MaxHealth: "..humanoid.MaxHealth)
end)
end)
end)
Above, is the setter. Like its name, it will set the data. Meaning, it changes the health to what it is supposed to be at.
Local Script in StarterPlayer>StarterPlayerScripts
local player = game.Players.LocalPlayer
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage:WaitForChild("remoteEvent")
local statsFolder = player:WaitForChild("Stats", 100)
local level = statsFolder:WaitForChild("Level")
remoteEvent:FireServer(level.Value)
level.Changed:Connect(function()
remoteEvent:FireServer(level.Value)
end)
Above is the getter. I don't think I need to explain how this works, it's just the opposite of the Script...
I hope this helped you, if it did, please mark this as the accepted answer to help other people. If you have any questions then comment!
ALSO: I recommended renaming your stats folder from Stats, to leaderstats. So you can use the built-in Roblox leaderboard...
1 comment
Please use variables lmao