Robbing game press 'E' isnt working

so i am making a robbing game if you press ‘E’ you should be robbing but it isn’t robbing i have no errors but there might be something wrong in it here is the script

local uis = game:GetService("UserInputService")
local robbing = false
local clicks = 25
local clicked = 0

uis.InputBegan:Connect(function(key, event)
	if key.KeyCode == Enum.KeyCode.E and not event then
		if (game.Players.LocalPlayer.Character.PrimaryPart.Position - script.Parent.Parent.Adornee.Position).Magnitude < 6 then
			robbing = true
			if clicked > clicks then
				script.Parent.Parent.Text.Text = "Robbing..."
				script.Parent.Visible = true
				clicked = clicked + 1
				script.Parent.Robber:TweenPosition(UDim2.new((clicked/clicks), 0, 1, 0) "Out", "Quad", 0.3, true)
				script.Parent.Robber.BackgroundColor3 = Color3.fromRGB(0, 255, 155)
				script.Parent.Robber.TextLabel.TextColor3 = Color3.fromRGB(0, 170, 73)
				if clicked == clicks and game.Workspace.RobPart.Open.Value == true then
					wait(0.3)
					script.Parent.Parent.Text.Text = "Robbery succes!"
					local amount = math.random(100, 200)
					script.Parent.Robber.TextLabel.Text = "+ $"..amount.."!"
					robbing = false
					game.ReplicatedStorage.RobStatus:FireServer(amount)
				elseif clicked == clicks and game.Workspace.RobPart.Open.Value == false then
					wait(0.3)
					script.Parent.Parent.Text.Text = "Robbery Failed!"
					script.Parent.Robber.BackgroundColor3 = Color3.fromRGB(197, 55, 55)
					script.Parent.Robber.TextLabel.TextColor3 = Color3.fromRGB(149, 41, 41)
					script.Parent.Robber.TextLabel.Text = "We have no money..."
					robbing = false
				end
			end
		end
	end
end)

wait(3)
while true do
	if (game.Players.LocalPlayer.Character.PrimaryPart.Position - script.Parent.Parent.Adornee.Position).Magnitude < 6 then
		script.Parent.Parent.Enabled = true
	else
		robbing = false
		script.Parent.Visible = true
		script.Parent.Parent.Text.Text = "Press E to Rob!"
		script.Parent.Robber.TextLabel.Text = ""
		clicked = 0
		script.Parent.Robber.Size = UDim2.new(0,0,1,0)
		script.Parent.Parent.Enabled = false
	end
	wait(0.3)
end
2 Likes

have you tried putting prints all over the place after every if or every Connect? I usually do that to check where the code breaks.

a script can break without showing errors?

yeah, mostly from if statements done wrong or Connects that are triggered at the wrong event.

this part isnt working
´´´
if (game.Players.LocalPlayer.Character.PrimaryPart.Position - script.Parent.Parent.Adornee.Position).Magnitude < 6 then
script.Parent.Parent.Enabled = true
else
robbing = false
script.Parent.Visible = true
script.Parent.Parent.Text.Text = “Press E to Rob!”
script.Parent.Robber.TextLabel.Text = “”
clicked = 0
script.Parent.Robber.Size = UDim2.new(0,0,1,0)
script.Parent.Parent.Enabled = false
end
wait(0.3)
end
´´´

i think its from the if statement

print((game.Players.LocalPlayer.Character.PrimaryPart.Position - script.Parent.Parent.Adornee.Position).Magnitude < 6)

hold on nothing is working at the moment

okay its working like before again

its printing correct

30charararcte

You have to add a = after stating the variables name. Replace that with:

local uis = game:GetService("UserInputService")

already did that hold on i will update the script

mh, have no clue about anything else?

It looks like in your if statement after you change the debounce to “true”, you are checking to see if the variable “clicked” is greater than “clicks”. It looks like you’ve set clicked to 0 and clicks to 25. Maybe change those around?

i tried to change it around it din’t do anything also no errors

What did you change it to? The clicked and clicks should switch places

yea i tried that but it din’t do anything

Hmm. I’ll take your code and test it later. Your logic for that if statement doesn’t make sense to me. Do you have anything in your code previously that increases the clicked value?

no i did not had anything to increase the clicked value

i am also just a beginner so it will prob look a bit weird for some stuff