I made a simple robbery system in 9 code lines

i made a simple robbery system for noobs of scripting

u need to make a part insert a proximity promt and a script
later you delete print hello world and put this :

local Prize = math.random(145, 3545)

script.Parent.ProximityPrompt.Triggered:Connect(function(player)
player.leaderstats.Money.Value = player.leaderstats.Money.Value + Prize
script.Parent.ProximityPrompt.Enabled = false
game.ReplicatedStorage.RoberySuccess:FireClient(player, Prize)
wait(math.random(46, 145))
script.Parent.ProximityPrompt.Enabled = true
end)
later u instert a remote function in replicated storage called RoberySucces
and you have it

7 Likes
local Prize = math.random(145, 3545)

script.Parent.ProximityPrompt.Triggered:Connect(function(player)
player.leaderstats.Money.Value = player.leaderstats.Money.Value + Prize
script.Parent.ProximityPrompt.Enabled = false
game.ReplicatedStorage.RoberySuccess:FireClient(player, Prize)
wait(math.random(46, 145))
script.Parent.ProximityPrompt.Enabled = true
end)

I formatted your code to make it easier to read.
Btw you can do this by typing ``` before and after your code.

5 Likes

oh thanks
but the question is the code is easy to do for noobs of scripting?

Code format part 2, document edition:

local Prize = math.random(145, 3545)

script.Parent.ProximityPrompt.Triggered:Connect(function(player)
    player.leaderstats.Money.Value = player.leaderstats.Money.Value + Prize
    script.Parent.ProximityPrompt.Enabled = false
    game.ReplicatedStorage.RoberySuccess:FireClient(player, Prize)
    wait(math.random(46, 145))
    script.Parent.ProximityPrompt.Enabled = true
end)

@TheRoblox8978
Yeah, it seems pretty simple to follow for new programmers! Couple things I should add/suggest:

  • I’d suggest adding some comments to know which line does what exactly (It won’t waste a line, but rather give an explanation of what each thing is)

    • Example:
--Hello this is a commented section!
workspace.Part.CanCollide = true --I will not waste this line until you press enter!
  • Personal preference but I’d recommend changing this
    player.leaderstats.Money.Value = player.leaderstats.Money.Value + Prize

To this:

    player.leaderstats.Money.Value += Prize

Saves a bit more code :wink:
Overall though, good job!

3 Likes

I think for this to be more useful to noobs, along with the formatting suggested here already, you’ll also need to tell them where to put the script(type of script/localscript) and where to put the proximity prompt within the Studio game explorer.

Also, what is RoberySuccess, how do you create that? (I’m not asking, I’m saying a noob will ask this). Where is this function that is being fired?

What are you robbing? Is this in an NPC, a cash register brick or model? Another player?