So I have a gun in my game with ammo(6 bullets) but i have a reloading script and it doesnt works

by the way the script is a server side script

Script:

local t = script.Parent
t.Equipped:Connect(function()
local char = t.Parent 
local p = game.Players:GetPlayerFromCharacter(char)
local pgui = p:WaitForChild("PlayerGui")
local ammo = pgui:WaitForChild("Ammo")
local label = ammo:WaitForChild("label")
local reloading = false
local bullets = t:WaitForChild("Bullets")
local userinput = game:GetService("UserInputService")
userinput.InputBegan:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.Keyboard then
		if input.KeyCode == Enum.KeyCode.R then
				if bullets.Value == 0 then
				if not reloading then
					reloading = true
					while reloading == true do
						label.Text = "Reloading..."
					end
					wait(2.5)
					reloading = false
					bullets.Value = 6
					end
				end
			end
		end
	end)
end)

I've never scripted a gun before so it might be bad.

2 comments

0

You can't use UserInputService on the server, neither can you use PlayerGui on the server

0

So should it be a local script?