Gui error with gun system

so im doing a gun system with modules and all

but these part are weird

function TouchInputController:ShowAimButton(show: boolean)
	self.gui.Buttons.AimButton.Visible = show
end
function GuiController:updateHitmarkerPosition(newPosition: UDim2, isZoomed: boolean)
	if isZoomed then
		self.reticleGui.Hitmarker.Position = newPosition
	else
		self.reticleGui.Hitmarker.Position = hitmarkerPosition
	end
end

its from 2 different scripts, and it says

ReplicatedStorage.Guns.Scripts.GuiController:131: attempt to index nil with ‘Hitmarker’

but in the scripts there are parts like:

self.reticleGui.Hitmarker.GroupTransparency = 0
	self.reticleGui.Hitmarker.UIScale.Scale = 2

and

self.gui.Buttons.ShootButton.InputBegan:Connect(function(inputObject: InputObject)

that worked when i wrote them at first, but i dont understand where’s the error

i mean why is it doing it only on these part that are new, and not the previous ones that i coded

Your self variable isn’t being passed through correctly then. Make sure that it is what it’s supposed to be, as the error suggests that self.reticleGui is nil.

1 Like

here are the 2 self:

Gui Controller:

local self = {
		gun = gun,
		gunGui = gunGui,
		reticleGui = reticleGui,
		hitmarkerScaleTween = hitmarkerScaleTween,
		hitmarkerTransparencyTween = hitmarkerTransparencyTween,
		enabled = false,
		leadingZeros = leadingZeros,
		ammo = 0,
		reloading = false,
		connections = {},
	}

TouchInputController

local self = {
		gun = gun,
		gui = touchGui,
		enabled = false,
		connections = {},
	}

these works with every other functions but not the 2 i sent before

i found the error, the script where i was calling these functions was having a self too, with the touchinputcontroller and the guicontroller inside, and i forgot to put self before the GuiController:UpdateHitmarkerPosition

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.