Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 3 years ago

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.

0
Please format your code, and tell us which parts aren't working/erroring. radiant_Light203 1166 — 3y
0
Did my answer work? If yes, do accept it. radiant_Light203 1166 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

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
0
I'm not sure 100% if it'll work, if it doesn't then comment here. radiant_Light203 1166 — 3y
0
player.leaderstats.PointsValue.Value This part is underlined in red. Incomplete statement: expected assignment or a function call. PrestoAnimo 0 — 3y
0
I've edited it, check again. radiant_Light203 1166 — 3y
0
leaderstats is not a valid member of Player "Players.PrestoAnimo" PrestoAnimo 0 — 3y
View all comments (5 more)
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. radiant_Light203 1166 — 3y
0
Line 40 PrestoAnimo 0 — 3y
0
Ok, I've edited it again. radiant_Light203 1166 — 3y
0
PointsValue is not a valid member of Folder "Players.PrestoAnimo.leaderstats" - Server - Script:11 PrestoAnimo 0 — 3y
0
I bet the error shows up once you stop testing. It shouldn't matter much then. Test from inside a published game. radiant_Light203 1166 — 3y
Ad

Answer this question