Adding a Rewards Multiplier to my Game

I’m adding a functionality to my game which multiplies the amount of xp and coins earned by the player when collecting coins and finishing levels related to the amount of already completed levels of the in their current play session (eg. 1.1x multiplier on coins and xp after having completed 10 levels, 1.2x for the next 20 levels after that, etc.) Though, I am baffling with the way in which I will go about adding this multiplier.

These are the current scripts I have so far. Each within its own finish brick/coin.

🟡 The coin collect script:
local RS = game:GetService("ReplicatedStorage"):WaitForChild("CoinCollect"):WaitForChild("CollectCoin")
local players = game:GetService("Players")

local RunService = game:GetService("RunService")

RunService.Heartbeat:Connect(function(step)
	local rotationAmount = math.rad(100 * step)

	script.Parent.CFrame = script.Parent.CFrame * CFrame.Angles(rotationAmount, 0, 0)
end)

local playershit = {}

script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		local player = players:GetPlayerFromCharacter(hit.Parent)

		if not table.find(playershit, player) then
			table.insert(playershit, player)

			local Value = script.Parent.Value.Value

			player.leaderstats.Coins.Value += Value

			RS:FireClient(player, Value)
		end
	end
end)

.

🏁The finish script:
local players = game:GetService("Players")
local RS = game:GetService("ReplicatedStorage"):WaitForChild("Elevator"):WaitForChild("Win")

local TeleportPart = game:GetService("Workspace").WaitingElevator.TeleportPart

local position = 0

local prize = 25
local bonusprize = 25

local finished = {}

script.Parent.Touched:Connect(function(hit)
	local Root = hit.Parent:findFirstChild("Humanoid")
	
	if Root.Parent ~= nil then
		
		local reward = prize
		
		Root.WalkSpeed=16
		
		local player = players:GetPlayerFromCharacter(hit.Parent)
		
		local RootPart = hit.Parent:FindFirstChild("HumanoidRootPart")
		
		if RootPart then
			RootPart.CFrame = game.Workspace:WaitForChild("ElevatorTeleport").CFrame
		end
		
		if not table.find(finished, player) then
			
			table.insert(finished, player)
			
			position += 1

			if position <= 3 then
				reward += bonusprize
			end

			player.leaderstats.Coins.Value += reward
			player.leaderstats.Wins.Value += 1
			player.leaderstats.XP.Value += reward
			
			RS:FireClient(player, position, reward)

		end
	end
end)

What can I do to optimize these two scripts, perhaps having all the code run on one main script instead of multiple within each coin/finish brick, in order to better accommodate for the addition of a multiplier functionality?

1 Like

Sorry I don’t understand what you mean by:

Are both of these scripts under each coin? Or are they under different objects?

Also, you can just multiply the reward.

image

Each coin contains it’s own collection script. The same goes for the endbricks as well