Datastore and Leaderstats Spill System with Multipliers

Hello everyone, so I’m currently making a spill system where a ProximityPrompt is activated and then it awards a player 1 point by default, but extra points if they have a point multiplier gamepass. I have been trying to figure this out for around an hour now, and have yet to manage to make it so a) the spill still dissapears, b) the right amount of points are awarded via the leaderstats and c) ensuring it saves to the datastore, this is proving to be the most difficult to cope with.

local DataStoreService = game:GetService("DataStoreService")
local PointsDataStore = DataStoreService:GetOrderedDataStore("APS_Points_1221")

local function awardPoints(player: Player, points: number)

	local leaderstats = player:FindFirstChild("leaderstats")
	if leaderstats and game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId, 27829750) and game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId, 27829710) then
		leaderstats.Points.Value = leaderstats.Points.Value + 10
	elseif game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId, 27829750) then
		leaderstats.Points.Value = leaderstats.Points.Value + 5
	elseif game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId, 27829710) then
		leaderstats.Points.Value = leaderstats.Points.Value + 2
	elseif leaderstats then
		leaderstats.Points.Value = leaderstats.Points.Value + 1
end

	task.defer(function()
		local success, err = pcall(function()
			PointsDataStore:IncrementAsync(player.UserId, points)
		end)

		if not success then
			warn("Error awarding points:", err)
		end
	end)
end

script.Parent.Triggered:Connect(function(Player)
	
	script.Parent.Parent.Transparency = 1
	script.Parent.Enabled = false
	
	if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(Player.UserId, 27829750) and game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId, 27829710) then
		awardPoints(Player, 10)
	elseif game:GetService("MarketplaceService"):UserOwnsGamePassAsync(Player.UserId, 27829750) then
		awardPoints(Player, 5)
	elseif game:GetService("MarketplaceService"):UserOwnsGamePassAsync(Player.UserId, 27829710) then
		awardPoints(Player, 2)
	elseif Player then
		awardPoints(Player, 1)
	
	wait (100)
	script.Parent.Parent.Transparency = 0.5
	script.Parent.Enabled = true
	end
end)

Any help, advice or moral support would be much appreciated!

Where is the points variable used in the function?

Where does that extra end come from? Did you mean to close the elseif chain from the function above?

This does all the stuff it does in the awardPoints function. Seems unnecessary

Again, where does that end come from? Did you mean to close it on the elseif chain again?

2 Likes