Hello developers, I’ve been trying to make a system where the Player would battle an NPC based on their power (A UI pops that has a Red frame inside it a green frame that it’s size property is increased from right to the center). When the player clicks his mouse it would increase the frame size (based on the player power VS the NPC power on the green frame) and every 3 seconds the NPC would also decrease the green frame based on the NPC power VS the player power.
The problem I’m facing is calculating how much the frame would increase/decrease. My current code covers all the functions/events. If anyone could help me with the math system It’d be really appreciated.
I’m trying to replicate the bar system as this game.
Code:
local module = {}
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RepModules = require(ReplicatedStorage:WaitForChild("Modules"))
local MainUI = script.Parent.Parent
local Formatter = require(RepModules:WaitForChild("Formatter"))
local RaceUI = MainUI.BottomUI.RaceUI
local Race = workspace:WaitForChild("Race")
local Camera = workspace.CurrentCamera
function module.StartRace(Player, NPC, NPCPower)
local PlayerClone = Player.Character:Clone()
local NpcCharacter = NPC:Clone()
PlayerClone.PrimaryPart.Position = Race:WaitForChild("PlayerPos").Position
NpcCharacter.PrimaryPart.Position = Race:WaitForChild("NPCPos").Position
NpcCharacter.Parent = workspace
PlayerClone.Parent = workspace
Camera.CameraType = Enum.CameraType.Scriptable
Camera.CFrame = workspace.Race.CameraPos.CFrame
MainUI.BottomUI.RaceUI.Visible = true
MainUI.BottomUI.RaceUI.NPCHolder.BikeAmount.Text = Formatter:FormatNumber(tostring(NPC:WaitForChild("NPCPower").Value))
MainUI.BottomUI.RaceUI.NPCHolder.BikeAmount.Text = Formatter:FormatNumber(tostring(Player:WaitForChild("leaderstats").Speed.Value))
Player:GetMouse().Button2Down:Connect(function()
-- Increase the Frame
end)
task.spawn(function()
while task.wait(3) do
-- Decrease the Frame
end
end)
end
return module