Hello fellow developers! I have a question I need some answers on… Boosting/Bonus System! I’ll be listing the questions I have down below:
A general overview of what I’m trying to achieve: So, if you have played bee swarm simulator, you should be familiar with their “Timed boosting system” for say, For 15 minutes, you get a certain boost where you collect 15% more pollen in this specific field, and so on.
How would I wrap my head around such a system? I have tried creating one but my efforts are in vain (Shown down below)
How would I set a timer for boosts? Like you get it for 15 minutes only and if you leave the game and come back 10 minutes later you will have 5 minutes left. I know this uses os.time and datastores but I seriously cannot understand how to use os.time. Every attempt I’ve tried always fails…
I’ll be listing the code I have tried for Problem 1:
Problem 1 (My take on the Boosting system))
game.Players.PlayerAdded:Connect(function(Player) -- Server script when player joins
--# Player Boost Test
local Folder2 = Instance.new("Folder",Player) -- Data is saved on Datastore2
Folder2.Name = "BoostsFile"
local ChopBoost = Instance.new("IntValue",Folder2)
ChopBoost.Name = "ChopBoost"
ChopBoost.Value = 1
local ConversionBoost = Instance.new("IntValue",Folder2)
ConversionBoost.Name = "ConversionBoost"
ConversionBoost.Value = 1
I realised when I was making this that I do not know how to mess around with percentages and I only can make up some multipliers.
This is a server script that runs in a knife when the knife chops an apple, it detects for any boosts.
if player:WaitForChild("BoostsFile"):FindFirstChild("ChopBoost").Value > 1 then
local BoostedAmount = Strength.Value * player:WaitForChild("BoostsFile"):FindFirstChild("ChopBoost").Value
pt.Text = "+"..BoostedAmount
print("Added +"..BoostedAmount.." To Player!")
local UnboostedAmount = Strength.Value
pt.Text = "+"..UnboostedAmount
player:WaitForChild("Stats").Apple.Value = player:WaitForChild("Stats").Apple.Value + UnboostedAmount
print("No Boosts Active! Added +"..UnboostedAmount.." To Player!")
I really really hope I can get the problems resolved with your help. Thank you ALL!
~ I also have another post I need help on a Questing system you can check out!
So for the example with bee swarm, you can use a Value. If the Player X bought it then gives him the Value with a ServerScript that count the time since he got it. Then when you gather the pollen, if the player has X Value then give AmountOfPollens * Percentages to this players. Do you get my idea?
Now for the question about datastore i can’t help you since i use DataStore2. Also i wouldn’t do os.time. What i would do is saving the Value and updating it when it changed. If you just change the Value when the player leave the server, you could give a IntValue with a child as a ServerScript. The IntValue would contains the Value of the Saved value insude datastore
I could for sure gives an example for the bought thingy. But for the DataStore, i wouldn’t be able to give an example as you need to learn how to use DataStore or DataStore2 first. I would suggest you to take a look at AlvinBlox, on youtube. He does some good tutorials and some of them are related to both DataStore and DataStore2
Once you clicked the part that gives the boost, it would change your IntValue inside the DS2. Once your Value inside DS2 has been changed, and if the Value ~= 0, then clone that Value, add a script which do Value -= 1 every second, parent the script to the cloned Value (which should Disabled set to false) and then parent the ClonedValue to the character. Do you got my idea?
The boosting part would contains a ClickDetector (because this is how i would do that but you can do it with something else).
local click = script.Parent
--Find the root of your Value inside your DS2
When you learned how to use DS2, you should have added a line for every Value, once they changed, it does save. So at this part of the BoostValue you could do:
local clone = BoostValue:Clone()
clone.Parent = character
local Counter = script:WaitForChild("ReduceValue") --It is a script which will just do Value -= 1 every second
Counter.Parent = clone
Counter.Disabled = false
You would play around with touch event or anything else to check if the player is gathering pollen. Once you got it, just do something like
local PollenCount = workspace:FindFirstChild(plr.Name):WaitForChild("PollenValue") --IntValue or NumberValue
local Collect = 1 --the amount of pollen you should get when you have no boost
if workspace:FindFirstChild(plr.Name):FindFirstChild("BoostValue") then
PollenCount += (Collect + (Collect * workspace:FindFirstChild(plr.Name):FindFirstChild("BoostValue").Value))
While I cannot help you with the rest of your problem I can teach you something very helpful and useful about percentages that will help with all other games.
Percentages are usually written in games like this: “15%” or “25%”
But the thing about a percentage is that it’s actually just a fancy fraction. So “15%” is actually just 15/100 and “25%” is 25/100.
So technically all you need to do is take the player’s stat and add the player’s stat times the fraction, like this:
To give a really concrete example you can see in your head, think about the following:
The player collects 3 pollen each time. You want to give the player a x2 pollen boost. That’s 100% MORE than they’re normally getting.
So you do the following:
pollen = 3
percent = 100
pollen = pollen*(1+percent/100)
-- the above is the same as the below --
pollen = 3*(1+100/100) --or--
pollen = 3*(2) --or--
pollen = 6 -- which is 100% MORE than 3
I hope this helps demystify percentages a bit, they’re actually super simple.