Robbery not working correctly [29 lines long]

  1. What do you want to achieve?
    If the player is on the criminal team and they trigger the proximity prompt, they will get money,
  2. What is the issue?
    Whenever the player escapes jail and becomes a criminal, it’ll automatically give them the money from the robbery.
  3. What solutions have you tried so far?
    I see the problem, I have it down as “if player.Team.Name == criminal then”, automatically giving them the money, but I have it in the proximity prompt stuff so idk how to fix it cause it should be only giving it to them if they triggered the proximity prompt.
local pps = game:GetService("ProximityPromptService")
local canrob = true

pps.PromptTriggered:Connect(function(pp, plr)
	if canrob == true then
		if plr.Team.Name == "Criminal" then
			local randomCash = math.random(50, 250)
			plr.leaderstats.Cash.Value += randomCash
			plr.leaderstats.Bounty.Value += 100
			canrob = false
			plr.PlayerGui.StoreRobbed.Enabled = true
			plr.PlayerGui.StoreRobbed.Frame.CashAmount.Text = randomCash
			script.Money:Play()
			wait(3)
			plr.PlayerGui.StoreRobbed.Enabled = false
		else
			plr.leaderstats.Cash.Value += 0
			plr.leaderstats.Bounty.Value += 0
		end
	else
		plr.leaderstats.Cash.Value += 0
		plr.leaderstats.Bounty.Value += 0
	end
end)

while true do
	wait(300)
	canrob = true
end

image

2 Likes

You forgot to check what prompt was triggered, also you don’t need to use ProximityPromptService for this, rather just do script.Parent.Triggered, change your script to:

local canrob = true

script.Parent.Triggered:Connect(function(plr)
	if canrob == true then
		if plr.Team.Name == "Criminal" then
			local randomCash = math.random(50, 250)
			plr.leaderstats.Cash.Value += randomCash
			plr.leaderstats.Bounty.Value += 100
			canrob = false
			plr.PlayerGui.StoreRobbed.Enabled = true
			plr.PlayerGui.StoreRobbed.Frame.CashAmount.Text = randomCash
			script.Money:Play()
			wait(3)
			plr.PlayerGui.StoreRobbed.Enabled = false
		else
			plr.leaderstats.Cash.Value += 0
			plr.leaderstats.Bounty.Value += 0
		end
	else
		plr.leaderstats.Cash.Value += 0
		plr.leaderstats.Bounty.Value += 0
	end
end)

while true do
	task.wait(300)
	canrob = true
end
1 Like

Oh!! Thank you! This will help a lot. :smiley:

Never mind, fixed the error, in line 3 you put “script.Parent.Triggered(function(plr)” instead of “script.Parent.Triggered:Connect(function(plr)”

1 Like

I’ll edit my post, but remember to mark something as solution (I wrote that on mobile and forgot to connect)

1 Like