I’m a scripter and working on a new game, i want to make a job leveling system that saves i will explain what i mean by this.
For example if you click a part you get 10 cash and if you click 20 times on the part you level up, if you level up you get 15 cash instead of 10 cash per click.
The problem is that I don’t have any idea how to start a job leveling system that saves.
Start by creating a table that keeps track of how many clicks have been done.
local Clicks = {}
Then, continue by making a function for each time a ClickDetector is clicked on.
local function onClicked(player)
local value = Clicks[player.Name]
Clicks[player.Name] = value + 1
end
ClickDetector.MouseClick:Connect(onClicked)
Then check for the Clicks count and if it reaches a certain value or more, they level up.
local levelTracker = {}
local function levelUp(plr)
local CurrentLevel = levelTracker[plr.Name]
levelTracker[plr.Name] = CurrentLevel + 1
--run any other code
end
local function onClicked(player)
local value = Clicks[player.Name]
Clicks[player.Name] = value + 1
if Clicks[player.Name] >= 20 then -- checks here
Clicks[player.Name] = Clicks[player.Name] - 20
levelUp(player, Clicks[player.Name])
end
--run any other code
end
Then run any code that should follow suit after.
Let me know if this helped, if it didn’t then I apologise for not being helpful to your issue.
That’s not difficult at all, in fact I have already included it in my previous code.
local function onClicked(player)
local value = Clicks[player.Name]
Clicks[player.Name] = value + 1
if Clicks[player.Name] >= 20 then -- checks here
Clicks[player.Name] = Clicks[player.Name] - 20
levelUp(player, Clicks[player.Name])
end
--run any other code
end
Ah so, I think you mean having it tell the player how many clicks they need, alright so…
Start by creating a Humanoid and parenting it to the Model that holds the main part that is clicked on. Then, name the part that the player clicks on “Head”.
Rename the model to whatever you please,
(the player will first see this before they begin clicking away).
Create a table yet again (ClicksNeeded in my example) and make it so that when a player first joins they need 0 and are level 0. Then when the player first clicks, change them to level 1 immediately and using the Levels array, make it so that at some point, the clicks needed gets its amount by using Levels[level].
local Level = {}
local Levels = {20,40,60,80,100}
local Model = -- put model location here
local function onClicked(player)
local value = Clicks[player.Name]
Clicks[player.Name] = value + 1
if Clicks[player.Name] >= 20 then -- checks here
Clicks[player.Name] = Clicks[player.Name] - 20
levelUp(player, Clicks[player.Name])
end
local value2 = ClicksNeeded[player.Name]
ClicksNeeded[player.Name] = ClicksNeeded[player.Name] - 1
Model.Name = “You need ”..ClicksNeeded[player.Name]..“ to reach ”..Level[player.Name] + 1
--run any other code
end
It is vital to note that this means that the count shown will depend on the last person who interacted with it (of course it is interchangeable between players because of the way I coded it).