The error occurs on line 49, I've tried many different ways to fix this issue, but its the same type of issue each time.

The model gets placed into workspace and then when I try and move it back it wont get placed in saying its a nil value?

21:55:38.333 - Players.ArtificialSystem.PlayerGui.Viewmodel:49: attempt to index local 'PrimaryGunParent' (a nil value)

--[						Variables						]]--   
local player = game.Players.LocalPlayer
local PlayerFolder = game.ServerStorage["18920BHAKJ_PlayerInventorys_1K12J3I1"]:FindFirstChild("Folder"..game.Players.LocalPlayer.UserId)
local GunFolder = PlayerFolder:FindFirstChild("GunFolder"..player.UserId)
local PrimaryValue = GunFolder.Primary
local SecondaryValue = GunFolder.Secondary
local UI = game:GetService("UserInputService")
debounce = true
local SecondaryGunParent = GunFolder:FindFirstChild(SecondaryValue.Value)
local PrimaryGunParent = GunFolder:FindFirstChild(PrimaryValue.Value)

--[[------------------------------------------]]--


--[[						Functions						]]--

function PrimaryGun()
	PrimaryGunParent.Parent = game.Workspace
	print(PrimaryGunParent.Name)

end

function SecondaryGun()
	SecondaryGunParent.Parent = game.Workspace
	print(SecondaryGunParent.Name)
end

--[[------------------------------------------]]--


--[[						Basically, when you press one and two ok						]]--

UI.InputBegan:connect(function(input)
local SecondaryGunParent = GunFolder:FindFirstChild(SecondaryValue.Value)
local PrimaryGunParent = GunFolder:FindFirstChild(PrimaryValue.Value)
if input.KeyCode == Enum.KeyCode.One then


	if GunFolder.Secondary.Value == game.Workspace then
		--going to gunfolder 
		SecondaryGunParent.Parent = GunFolder
	elseif SecondaryGunParent.Parent == GunFolder then
		--going to workspace
		PrimaryGunParent.Parent = game.Workspace
	end

elseif input.KeyCode == Enum.KeyCode.Two then
	if PrimaryGunParent.Parent == game.Workspace then
--moved to gun folder
		
		PrimaryGunParent.Parent = GunFolder
	elseif PrimaryGunParent.Parent == GunFolder then
		SecondaryGunParent.Parent = game.Workspace
--Secondary gun is in workspace
	end
end
end)
		
	
--[[----------------------------------------------------------------------------------]]--

4 comments

0

Use :Connect and not :connect. Also, ServerStorage can't be used on the client. Either use a remote event to access it or put the gun in replicated storage

0

There isn't any code on line 49 but your error says line 49. did you edit your code or something?

0

Oh you meant line 48.

0

My bad, It was probably because I removed some blank space.