hey can you help me explain what and how the attempt to index nil with ‘inputbegan’ works
here is the code I used:
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