Gun script not working

So recently I am making a gun.

I typed all the scripts and tested it it doesn’t work.

Here is the output -
output 1.

here is the script -

local player = game:GetService("Players").LocalPlayer
local playerGui = player:WaitForChild("PlayerGui")
local tool = script.Parent.Parent

-- configs and varibles

local configs = script.Parent.Parent:WaitForChild("Configs")
local ammo = configs:WaitForChild("Ammo")
local reserveAmmo = configs:WaitForChild("ReserveAmmo")
local magSize = configs:WaitForChild("MagSize")

-- UI's
local Gui = script:WaitForChild("Gui")
local Frame = script.Gui:WaitForChild("AmmoFrame")
local ammolabel = Frame:WaitForChild("Ammo")
local reserveAmmoLabel = Frame:WaitForChild("ReserveAmmo")


-- functions
local function update()
	ammolabel.Text = tostring(ammo.Value)
	reserveAmmoLabel = tostring(reserveAmmo.Value)

	 if ammo.Value < math.floor(magSize.Value * 0.2) then
		ammolabel.TextColor3 = Color3.fromRGB(200, 0, 0)
	else
		ammolabel.TextColor3 = Color3.fromRGB(255, 255, 255)
	end
	
	if reserveAmmo.Value < math.floor(magSize.Value * 0.2) then
		reserveAmmoLabel.TextColor3 = Color3.fromRGB(255, 0, 0)
	else
		reserveAmmoLabel.TextColor3 = Color3.fromRGB(255, 255, 255) -- this is the error part
	end
end

-- eventlistener
ammo.Changed:Connect(update)
reserveAmmo.Changed:Connect(update)
tool.Equipped:Connect(function()
	Gui.Parent = playerGui
	update()
end)

tool.Unequipped:Connect(function()
	Gui.Parent = script
end)
--initialize
update()

My explorer(might be helpful) -
explorer 2.

(I have not included the gun parts.but ask me if I want to include them)

The GuiScripts is the one that I am coding RN

(post withdrawn by author, will be automatically deleted in 1 hour unless flagged)

Try using “Color3.new()” insteadof Color3.fromRGB().

So here’s the entire script with just that changed (just copy and paste it in and let me know how it goes):

local player = game:GetService("Players").LocalPlayer
local playerGui = player:WaitForChild("PlayerGui")
local tool = script.Parent.Parent

-- configs and varibles

local configs = script.Parent.Parent:WaitForChild("Configs")
local ammo = configs:WaitForChild("Ammo")
local reserveAmmo = configs:WaitForChild("ReserveAmmo")
local magSize = configs:WaitForChild("MagSize")

-- UI's
local Gui = script:WaitForChild("Gui")
local Frame = script.Gui:WaitForChild("AmmoFrame")
local ammolabel = Frame:WaitForChild("Ammo")
local reserveAmmoLabel = Frame:WaitForChild("ReserveAmmo")


-- functions
local function update()
	ammolabel.Text = tostring(ammo.Value)
	reserveAmmoLabel = tostring(reserveAmmo.Value)

	 if ammo.Value < math.floor(magSize.Value * 0.2) then
		ammolabel.TextColor3 = Color3.new(200, 0, 0)
	else
		ammolabel.TextColor3 = Color3.new(255, 255, 255)
	end
	
	if reserveAmmo.Value < math.floor(magSize.Value * 0.2) then
		reserveAmmoLabel.TextColor3 = Color3.new(255, 0, 0)
	else
		reserveAmmoLabel.TextColor3 = Color3.new(255, 255, 255) -- this is the error part
	end
end

-- eventlistener
ammo.Changed:Connect(update)
reserveAmmo.Changed:Connect(update)
tool.Equipped:Connect(function()
	Gui.Parent = playerGui
	update()
end)

tool.Unequipped:Connect(function()
	Gui.Parent = script
end)
--initialize
update()
1 Like

I think you should add there

reserveAmmoLabel.Text = tostring(reserveAmmo.Value)
3 Likes

Ahhh I believe @iFlameyz is correct, that would explain the error saying that you’re trying to index a string, not a TextLabel.

1 Like