#Why does this crash my Game?
5 messages · Page 1 of 1 (latest)
local reloading = false
local UIS = game:GetService("UserInputService")
local Ammo = 32
--Crosshair Appearing
script.Parent.Equipped:Connect(function()
game.ReplicatedStorage.GunValue.Value = true
end)
script.Parent.Unequipped:Connect(function()
game.ReplicatedStorage.GunValue.Value = false
end)
M = game.Players.LocalPlayer:GetMouse()
--Shooting/Ammo
script.Parent.Activated:Connect(function()
while M.Button1Down and wait(0.1) do
wait(0.1)
if Ammo > 0 and reloading == false then
wait(0.1)
game.Workspace.pistol_fire:Play()
Ammo = Ammo - 1
game.ReplicatedStorage.AmmoInMag.Value = Ammo
local MOUSEPOS = game.Players.LocalPlayer:GetMouse()
if reloading == false and MOUSEPOS.Target.Parent:FindFirstChild("Humanoid") then
print("PLAYER")
MOUSEPOS.Target.Parent.Humanoid.Health = MOUSEPOS.Target.Humanoid.Health - 10
end
end
end
end)
local equiped = false
script.Parent.Equipped:Connect(function()
print("Equipped")
equiped = true
end)
script.Parent.Unequipped:Connect(function()
equiped = false
end)
--Reload Script
UIS.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.R and equiped == true then
print("RELOAD")
game.Workspace["Pistol Reload Sound"]:Play()
reloading = true
Ammo = 32
wait(1.5)
reloading = false
game.ReplicatedStorage.AmmoInMag.Value = Ammo
end
end) -- Thats all my code
could you provide more information? what's the error message? does it show you the line where it goes wrong?
it's probably the while loop
try to provide more information
** You are now Level 1! **