In these problems you have to deal with sub-problems (in most cases). The simplest way to solve these problems is to split them into these sub-problems, otherwise the task will be too complex. The more you script, the bigger "sub-problems" you can deal with.
Let's check it out. We basically have two main problems:
1) Showing a GUI how much hits we need
2) Showing the numbers of rock into the leaderboard
We can split these up in sub-problems:
1)
a) Show a GUI with text on how many hits we need
b) Transfer brick to inventory
c) Find a way to store how much hits one has done on the block
2)
a) Create leaderstats
b) Update number
Problem 1a
The best way to program all these problems is to define variables to add functionality. As I don't know where you GUI is stored, I will provide "hooks", which will have to do a defined action (such as putting text on the GUI where you want it). You have to make sure these hooks work correctly.
2 | return game.ReplicatedStorage.HitsNeededGUI:Clone() |
8 | gui.Parent = game.Players.LocalPlayer.PlayerGui |
Problem 1b
We only need to copy the rock to an inventory. UpdateLeaderstats is a hook for problem 2.
1 | function TransferBlock(Block) |
2 | Block.Parent = game.Players.LocalPlayer.Inventory |
3 | UpdateLeaderstats(Block) |
Problem 1c
The best way to store this - also when a player has resetted for example - is to store a value into the block itself. A problem is that 2 players can then "mine" a brick faster. I guess that we don't want this?
01 | function GetIdentifier() |
02 | return game.Players.LocalPlayer.Name |
05 | function BlockHit(Block, Tool) |
06 | local ident = GetIdentifier() |
07 | if Block:FindFirstChild(ident) then |
08 | Block [ ident ] .Value = Block [ ident ] .Value + 1 |
10 | local new = Instance.new( "NumberValue" , Block) |
14 | if Block [ ident ] .Value > 5 then |
Problem 2a
Initialize the leaderstats
1 | local leaderstats = Instance.new( "Model" , game.Players.LocalPlayer) |
2 | leaderstats.Name = "leaderstats" |
3 | local rocks = Instance.new( "NumberValue" , leaderstats) |
Problem 2b
We receive which we receive, and then update the leaderstats accordingly
1 | function UpdateLeaderstats(Block) |
2 | if Block.Name = = "Rock" then |
3 | rocks.Value = rocks.Value + 1 |
The important thing about all this is to think in hooks. If you create tiny functions which should do the expected thing you can upscale everything later. This is one of the main things I learned, after one of my biggest games became unhandlable due the fact I had scripted it without thinking in subproblems.
Locked by FearMeIAmLag
This question has been locked to preserve its current state and prevent spam and unwanted comments and answers.
Why was this question closed?