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

How do i make an armor that actually saves? (API services are enabled)

			game.Players.PlayerAdded:Connect(function(Character)
				Character.CharacterAdded:Connect(function()
					if game.ReplicatedStorage.TankArmorBought.Value == true then
						Plr.Character.Humanoid.MaxHealth = 200
						Plr.Character.Humanoid.Health = 200
						Plr.Character.Humanoid.WalkSpeed = 10
					end
				end)
				end)
		end
	end)
end)

and heres the datastore script:

local DSS = game:GetService("DataStoreService")
local DS2 = DSS:GetDataStore("TankArmorBought")
game.Players.PlayerAdded:Connect(function(Plr)
	print("Getting")
	game.ReplicatedStorage.TankArmorBought.Value = DS2:GetAsync(Plr.UserId)
	print("Got Value")
	game.Players.PlayerRemoving:Connect(function()
		print("Saving")
		DS2:SetAsync(Plr.UserId, game.ReplicatedStorage.TankArmorBought.Value)
		print("Saved")
	end)
	end)

1 answer

I know your first script has more code above that we can't see, but I can see the issue in your second script.

You have your PlayerRemoving event nested inside your PlayerAdded event. Quite honestly, I have no idea what results that would even produce. That's just confusing. At any rate, it's not what you really meant to do. These functions should be entirely separate.

local DSS = game:GetService("DataStoreService")
local DS2 = DSS:GetDataStore("TankArmorBought")

game.Players.PlayerAdded:Connect(function(Plr)
    print("Getting")
    game.ReplicatedStorage.TankArmorBought.Value = DS2:GetAsync(Plr.UserId)
    print("Got Value")
end)

game.Players.PlayerRemoving:Connect(function(Plr) -- you also left out the "Plr" here
        print("Saving")
        DS2:SetAsync(Plr.UserId, game.ReplicatedStorage.TankArmorBought.Value)
        print("Saved")
end)

2 comments

0

thanks the leaderstats script is cleaner now but the effects dont save

0

Are there any errors? And is this a Server Script?

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