Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Health changing server script not working?

There are no errors, and it wont work. Can someone help? I put it in my leaderstats script, heres the full script:

local ds = game:GetService("DataStoreService")
local ds1 = ds:GetDataStore("GoldSaveSystem")
local ds2 = ds:GetDataStore("ExperienceSaveSystem")
local ds3 = ds:GetDataStore("LevelSaveSystem")

game.Players.PlayerAdded:Connect(function(player)

	local folder = Instance.new("Folder", player)
	folder.Name = "leaderstats"

	local Gold = Instance.new("IntValue", folder)
	Gold.Name = "Gold"

	local Experience = Instance.new("IntValue", folder)
	Experience.Name = "Experience"

	local Level = Instance.new("IntValue", folder)
	Level.Name = "Level"

	Gold.Value = ds1:GetAsync(player.UserId) or 0
	ds1:GetAsync(player.UserId, Gold.Value)

	Experience.Value = ds2:GetAsync(player.UserId) or 0
	ds2:GetAsync(player.UserId, Experience.Value)

	Level.Value = ds3:GetAsync(player.UserId) or 1
	ds3:GetAsync(player.UserId, Level.Value)
	
player.CharacterAdded:Connect(function(character)
	character.Humanoid.MaxHealth = 100 * (Level.Value +1)
		character.Humanoid.Health = player.Character.MaxHealth
	end)
	
	Experience.Changed:Connect(function()
		if Experience.Value >= 100 * (Level.Value +1) then
			Experience.Value = 0
			Level.Value = Level.Value +1
		end
	end)

	Level.Changed:Connect(function()
		player.Character.Humanoid.MaxHealth = 100 * (Level.Value)
		player.Character.Humanoid.Health = 100 * (Level.Value)
	end)
end)

game.Players.PlayerRemoving:Connect(function(player)

	local Gold = player.leaderstats.Gold
	local Experience = player.leaderstats.Experience
	local Level = player.leaderstats.Level

	ds1:SetAsync(player.UserId, Gold.Value)
	ds2:SetAsync(player.UserId, Experience.Value)
	ds3:SetAsync(player.UserId, Level.Value)
end)

And heres the part that wont work

player.CharacterAdded:Connect(function(character)
	character.Humanoid.MaxHealth = 100 * (Level.Value +1)
		character.Humanoid.Health = player.Character.MaxHealth
	end)

1 answer

Did turn on API services in studio settings? Without this, Datastore won't work in studio.

1 comment

0

I did. I turned HTTPS and API on.

This discussion is preserved as it was. New answers, comments, and votes are closed.