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

How can I make it to where this saves points, but gives points every 5 minutes?

local DSS = game:GetService("DataStoreService") local Points = DSS:GetDataStore("Points")

game.Players.PlayerAdded:Connect(function(plr) local pPoints = Points:GetAsync(plr.UserId) or 10 local leaderstats = Instance.new("Folder",plr) leaderstats.Name = "leaderstats" local PointsValue = Instance.new("NumberValue") PointsValue.Name = "Points" PointsValue.Value = pPoints PointsValue.Parent = leaderstats while wait(300) do PointsValue.Value = PointsValue.Value +5 end PointsValue.Changed:connect(function(v) Points:SetAsync(plr.UserId,v) print("Points Saved!") end) end)

(I got help from a youtube video)

Also, how can I make this add points after a successful purchase?

local ID = 00000000 local MarketplaceService = game:GetService("MarketplaceService")

script.Parent.MouseButton1Click:Connect(function() MarketplaceService:PromptGamePassPurchase(game.Players.LocalPlayer,ID) end)

(Help from somewhere else)

Sorry if I'm asking too much!! All the Discord servers I'm in won't help, and I can't seem to figure it out.

2 comments

0

Please format your code, and tell us which parts aren't working/erroring.

0

Did my answer work? If yes, do accept it.

1 answer

I'll be answering only the title. If it were me, I'd do it like this:

local DataStoreService = game:GetService("DataStoreService")
local Players = game:GetService("Players")

local PointsStore = DataStoreService:GetDataStore("Points")

Players.PlayerRemoving:Connect(function(player)
	local success, errorMessage = pcall(function()
		PointsStore:SetAsync(player.UserId, player.leaderstats.PointsValue.Value)
	end)

	if not success then warn(errorMessage) end
end)

Players.PlayerAdded:Connect(function(player)
	local success, points = pcall(function()
		return PointsStore:GetAsync(player.UserId)
	end)

	if success then
		local leaderstats = Instance.new("Folder", player)
		leaderstats.Name = "leaderstats"

		local pointsValue = Instance.new("NumberValue", leaderstats)
		pointsValue.Name = "Points"
		pointsValue.Value = points
	else
		local leaderstats = Instance.new("Folder", player)
		leaderstats.Name = "leaderstats"

		local pointsValue = Instance.new("NumberValue", leaderstats)
		pointsValue.Name = "Points"
		pointsValue.Value = 0
	end
end)

while true do
	wait(300)

	for _,player in pairs(Players:GetPlayers()) do
		player.leaderstats.PointsValue.Value += 50
	end
end

9 comments

0

I'm not sure 100% if it'll work, if it doesn't then comment here.

0

player.leaderstats.PointsValue.Value This part is underlined in red. Incomplete statement: expected assignment or a function call.

0

I've edited it, check again.

0

leaderstats is not a valid member of Player "Players.PrestoAnimo"

0

Which line does this error show up at? In any case, try my revisions again. I forgot to account for a case where the player has no data to load.

0

Line 40

0

Ok, I've edited it again.

0

PointsValue is not a valid member of Folder "Players.PrestoAnimo.leaderstats" - Server - Script:11

0

I bet the error shows up once you stop testing. It shouldn't matter much then. Test from inside a published game.

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