i been coding a gun for a while and im having a problem with one script
can anyone help me?
local maxAmmo = 10
local Ammo = maxAmmo
local reloading = false
local Player = game.Players.PlayerAdded
local PlayerGui = Player:WaitForChild(“PlayerGui”)
local textLabel = PlayerGui:WaitForChild(“AmmoDisplay”):FindFirstChild(“AmmoText”)
script.Parent.Equipped:Connect(function(Mouse)
local function reload()
reloading = true
wait(1)
Ammo = maxAmmo
reloading = false
end
script.Parent.Activated:Connect(function()
if Ammo > 0 and not reloading then
Ammo = Ammo - 1
script.Parent.Gunshot:Play()
if mouse.Target.Parent:FindFirstChild("Humanoid")then
script.Parent.DealDamage:FireServer(Mouse.Target.Parent, 20)
end
elseif reloading == false then
(reload()
script.Parent.GunShot:Stop()
end
while wait()do
textLabel.Text = (Ammo).."/"..maxammo
end
end)
local input = game:GetService("UserInputService")
input.inputBegan:Connect(function(key)
if key.keyCode == Enum.KeyCode.R and reloading == false and Ammo ~= maxAmmo then
reload()
end
end)
local maxAmmo = 10
local Ammo = maxAmmo
local reloading = false
local Player = game.Players.PlayerAdded
local PlayerGui = Player:WaitForChild(“PlayerGui”)
local textLabel = PlayerGui:WaitForChild(“AmmoDisplay”):FindFirstChild(“AmmoText”)
script.Parent.Equipped:Connect(function(Mouse)
local function reload()
reloading = true
wait(1)
Ammo = maxAmmo
reloading = false
end
script.Parent.Activated:Connect(function()
if Ammo > 0 and not reloading then
Ammo = Ammo - 1
script.Parent.Gunshot:Play()
if mouse.Target.Parent:FindFirstChild("Humanoid")then
script.Parent.DealDamage:FireServer(Mouse.Target.Parent, 20)
end
elseif reloading == false then
(reload()
script.Parent.GunShot:Stop()
end
while wait()do
textLabel.Text = (Ammo).."/"..maxammo
end
end)
local input = game:GetService("UserInputService")
input.inputBegan:Connect(function(key)
if key.keyCode == Enum.KeyCode.R and reloading == false and Ammo ~= maxAmmo then
reload()
end
end)
Aha! I see. When using a function which in this case is script.Parent.Activated:Connect(function(), your end needs to have ) so your error is that end should be end)
local maxAmmo = 10
local Ammo = maxAmmo
local reloading = false
local Player = game.Players.PlayerAdded
local PlayerGui = Player:WaitForChild(“PlayerGui”)
local textLabel = PlayerGui:WaitForChild(“AmmoDisplay”):FindFirstChild(“AmmoText”)
script.Parent.Equipped:Connect(function(Mouse)
local function reload()
reloading = true
wait(1)
Ammo = maxAmmo
reloading = false
end
end)
script.Parent.Activated:Connect(function()
if Ammo > 0 and not reloading then
Ammo = Ammo - 1
script.Parent.Gunshot:Play()
if mouse.Target.Parent:FindFirstChild("Humanoid")then
script.Parent.DealDamage:FireServer(Mouse.Target.Parent, 20)
end
elseif reloading == false then
reload()
script.Parent.GunShot:Stop()
end
while wait() do
textLabel.Text = (Ammo).."/"..maxAmmo
end
end)
local input = game:GetService("UserInputService")
input.inputBegan:Connect(function(key)
if key.keyCode == Enum.KeyCode.R and reloading == false and Ammo ~= maxAmmo then
reload()
end
end)