Gun script not work

Does this work? Please tell me if so.

sadly no :frowning_face: i see no output error

is this supposed to be (reload() or reload()

hmmmm i think no ima try that :thinking:

1 Like

hey remember you said to change the end to end) it has a error

What error because that should be right.

image

should i give you the whole script? in image

You need Two ends thats another error

script.Parent.Equipped:Connect(function(Mouse)
local function reload()
reloading = true
wait(1)
Ammo = maxAmmo
reloading = false
end

should be

script.Parent.Equipped:Connect(function(Mouse)
local function reload()
reloading = true
wait(1)
Ammo = maxAmmo
reloading = false
end
end)

and if possible, I would love the full script

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)

Try this I think it will work like it is supposed to

having problems at local PlayerGui = Player:WaitForChild(“PlayerGui”)

(player:WaitForChild)

I don’t really understand what you need playergui for though try deleting it

so i have this ammo thing that tells you how much you have

oh ok but could you not do that in a local script? otherwise everyones ammo will be the same. Also, you might wanna try having a few intVals inside your gun so you can just call on them when you need, that way it will be easy to get the variable of Ammo.

Player Gui elements doesn’t work on server script. You need to code the player GUI on the local script and use remote events to communicate across client / server.

IK THATS WHAT I JUST SAID! hmph. :expressionless:

fixed it guy sorry :grinning: and sorry