Gem Multiplier Not Working

I have a leaderstats script, and inside of it is a reward for players when they kill someone. The rewards multiply if a player has a certain amount of wins, however, I have a gamepass which also stacks 1.5x gem multiplier if owned and it doesn’t seem to work. This is the script I’m using;

local DataStoreService = game:GetService("DataStoreService")
local SaveDatastore = DataStoreService:GetDataStore("SaveDatastore")
local marketplaceService = game:GetService("MarketplaceService")

game.Players.PlayerAdded:Connect(function(Player)
	
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = Player

	local Gems = Instance.new("IntValue")
	Gems.Name = "Gems"
	Gems.Value = 0
	Gems.Parent = leaderstats

	local Wins = Instance.new("IntValue")
	Wins.Name = "Wins"
	Wins.Value = 0
	Wins.Parent = leaderstats

	local Data
	local Success, ErrorMessage = pcall(function()
		Data = SaveDatastore:GetAsync(Player.UserId)
	end)
	if Success then
		Gems.Value = Data.Gems or 0
		Wins.Value = Data.Wins or 0
		print("Successfully loaded data")
	else
		print("There was an error loading data")
		warn(ErrorMessage)
	end

	Player.CharacterAdded:Connect(function()
		local Humanoid = Player.Character:WaitForChild("Humanoid")
		Humanoid.Died:Connect(function()
			print("died")
			Player:SetAttribute("Team",nil)
			local DamageDealer = Humanoid:FindFirstChild("creator")

			if DamageDealer and DamageDealer.Value then
				local Killer = game.Players:FindFirstChild(DamageDealer.Value.Name)

				if Killer and Killer.leaderstats then
					local Gems = Killer.leaderstats:FindFirstChild("Gems")
					if Gems then 
						local multiplier = 1
						if Killer.leaderstats:FindFirstChild("Wins") then
							local winsValue = Killer.leaderstats.Wins.Value
							if winsValue >= 10 then
								multiplier = 1.35
							end
							if winsValue >= 25 then
								multiplier = 1.5
							end
							if winsValue >= 50 then
								multiplier = 2
							end
							if winsValue >= 75 then
								multiplier = 2.55
							end
							if winsValue >= 100 then
								multiplier = 3
							end
							if winsValue >= 125 then
								multiplier = 3.25
							end
							if winsValue >= 150 then
								multiplier = 3.7
							end
							if winsValue >= 175 then
								multiplier = 4.1
							end
						end
						
						local ownsVIP = marketplaceService:UserOwnsGamePassAsync(Player.UserId, 793729840)
						if ownsVIP == true then
							multiplier += 1.5
						end
						Gems.Value = (Gems.Value or 0) + 5 * multiplier
						print(multiplier)
					end
				end
			end
		end)
	end)
end)


game.Players.PlayerRemoving:Connect(function(Player)
	local Data = {
		Gems = Player.leaderstats.Gems.Value,
		Wins = Player.leaderstats.Wins.Value
	}
	local Success, ErrorMessage = pcall(function()
		SaveDatastore:SetAsync(Player.UserId, Data)
	end)
	if Success then
		print("Successfully saved data")
	else
		print("There was an error saving data")
		warn(ErrorMessage)
	end
end)

I do not get the additional multiplier for owning the gamepass and I was wondering if anyone had any advice or tips on how to fix this, also please ignore the messiness of the script I know there’s alot of other ways to do this - this is just how I chose to write it as a beginner! Thanks alot. :happy3:

1 Like

Bump, still need help with this if possible

1 Like

Can you add a print(ownsVIP) before the if statement?

1 Like

Just did so, didn’t seem like anything printed out.

1 Like

Resolved, just had to change the Player in local ownsVIP = marketplaceService:UserOwnsGamePassAsync(Player.UserId, 793729840) to Killer.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.