Include a standalone, bare-bones rbxl file with only the code you want reviewed.
- Code Review is for reviewing specific parts of your code, and not your whole game.
- Code Review is intended for improving already-working code. If you need help debugging your code, please use Scripting Support.
Provide an overview of:
- What does the code do and what are you not satisfied with?
the code its mean so when a part touches anoter whit an specific name it gives you points and also activate some other effects and i want to make an easier way to detect which mineral is touching - What potential improvements have you considered?
less code so i can be changed more easily and not be repetitive - How (specifically) do you want to improve the code?
I want it to be less messy so i can change it for the future
local sound1 = script.Parent.BreakSound
local sound2 = script.Parent.BreakSound2
local sounds = {sound1,sound2}
local player = game.Players:GetPlayerFromCharacter(script.Parent.Parent.Parent.Parent)
function onTouch(hit)
if hit.Parent.Name:match("Rock") then
player.leaderstats.Coins.Value = player.leaderstats.Coins.Value+2
print('Player mined a '.. hit.Parent.Name)
sounds[math.random(1, #sounds)]:Play()
script.Parent.RockBreaking:Play()
script.Disabled = true
hit.Parent.MovingModel.Disabled = false
hit.Parent.Particles.Disabled = false
hit.Parent.Life.Value = hit.Parent.Life.Value-25
if hit.Parent.Life.Value < 1 then
player.leaderstats.Coins.Value = player.leaderstats.Coins.Value+20
script.Parent.RockFinalBreak:Play()
local fog = game.ServerStorage.RockBreakedFog:Clone()
fog.Parent = workspace
fog.Position = hit.Parent.pos.Position
fog.Script.Enabled = true
hit.Parent:Destroy()
end
end
if hit.Parent.Name:match("Metal") then
player.leaderstats.Coins.Value = player.leaderstats.Coins.Value+3
print('Player mined a '.. hit.Parent.Name)
sounds[math.random(1, #sounds)]:Play()
script.Parent.RockBreaking:Play()
script.Disabled = true
hit.Parent.MovingModel.Disabled = false
hit.Parent.Particles.Disabled = false
hit.Parent.Life.Value = hit.Parent.Life.Value-25
if hit.Parent.Life.Value < 1 then
player.leaderstats.Coins.Value = player.leaderstats.Coins.Value+35
script.Parent.RockFinalBreak:Play()
local fog = game.ServerStorage.RockBreakedFog:Clone()
fog.Parent = workspace
fog.Position = hit.Parent.pos.Position
fog.Script.Enabled = true
hit.Parent:Destroy()
end
end
end
script.Parent.Touched:Connect(onTouch)
sorry if the code is messy im kinda new to triying to improve my code