Player becomes nil in module script

Am trying to make a hotbar system, when it passes it becomes nil for some reason. I tried to fix it for about a hour now but still doesnt work. Here is the scripts (btw it is still incomplete so it doesnt account for another numbers yet):

Server Script In ServerScriptService:

local Players = game:GetService("Players")

local EventNone = game.ReplicatedStorage.Events.Hotbar.NoneEquipped
local EventFalse = game.ReplicatedStorage.Events.Hotbar.EquippedFalse
local EventTrue = game.ReplicatedStorage.Events.Hotbar.EquippedTrue

local Module = require(game.ServerStorage.Module:WaitForChild("HotbarModule"))

EventNone.OnServerEvent:Connect(function(player, Input)
	print(Input)
	local GUI2 = player.PlayerGui.HotbarFrame
	local HotbarFrame = GUI2.HotbarFrame
	local h1 = HotbarFrame.Hotbar1
	local h2 = HotbarFrame.Hotbar2
	local h3 = HotbarFrame.Hotbar3
	local h4 = HotbarFrame.Hotbar4
	local h5 = HotbarFrame.Hotbar5
	local h6 = HotbarFrame.Hotbar6
	local h7 = HotbarFrame.Hotbar7

	if Input == 1 then
		print(player)
		Module.EventNone(player, Input)
	end
end)


EventFalse.OnServerEvent:Connect(function(player, Input)

	print(Input)
	local GUI2 = player.PlayerGui.HotbarFrame
	local HotbarFrame = GUI2.HotbarFrame
	local h1 = HotbarFrame.Hotbar1
	local h2 = HotbarFrame.Hotbar2
	local h3 = HotbarFrame.Hotbar3
	local h4 = HotbarFrame.Hotbar4
	local h5 = HotbarFrame.Hotbar5
	local h6 = HotbarFrame.Hotbar6
	local h7 = HotbarFrame.Hotbar7

	if Input == 1 then
		print(player)
		Module.EventFalse(player, Input)
	end
end)

EventTrue.OnServerEvent:Connect(function(player, Input)
	print(Input)
	local GUI2 = player.PlayerGui.HotbarFrame
	local HotbarFrame = GUI2.HotbarFrame
	local h1 = HotbarFrame.Hotbar1
	local h2 = HotbarFrame.Hotbar2
	local h3 = HotbarFrame.Hotbar3
	local h4 = HotbarFrame.Hotbar4
	local h5 = HotbarFrame.Hotbar5
	local h6 = HotbarFrame.Hotbar6
	local h7 = HotbarFrame.Hotbar7

	if Input == 1 then
		print(player)
		Module.EventTrue(player, Input)
	end
end)

Module Scripts In ServerStorage:

local module = {}

function module:EventNone(player, Input)
	print(player)
	local GUI2 = player.PlayerGui.HotbarFrame
	local HotbarFrame = GUI2.HotbarFrame
	local h1 = HotbarFrame.Hotbar1
	local h2 = HotbarFrame.Hotbar2
	local h3 = HotbarFrame.Hotbar3
	local h4 = HotbarFrame.Hotbar4
	local h5 = HotbarFrame.Hotbar5
	local h6 = HotbarFrame.Hotbar6
	local h7 = HotbarFrame.Hotbar7
	
	h1:SetAttribute("Equipped", false)
	if player.Character:FindFirstChildWhichIsA("Tool") or player.Backpack:FindFirstChildWhichIsA("Tool") then
		local Tool = player.Character:FindFirstChildWhichIsA("Tool") or player.Backpack:FindFirstChildWhichIsA("Tool")
		Tool.Parent = player.Inventory
	end
end

function module:EventFalse(player, Input)
	print(player)
	local GUI2 = player.PlayerGui.HotbarFrame
	local HotbarFrame = GUI2.HotbarFrame
	local h1 = HotbarFrame.Hotbar1
	local h2 = HotbarFrame.Hotbar2
	local h3 = HotbarFrame.Hotbar3
	local h4 = HotbarFrame.Hotbar4
	local h5 = HotbarFrame.Hotbar5
	local h6 = HotbarFrame.Hotbar6
	local h7 = HotbarFrame.Hotbar7
	
	for i, v in pairs(HotbarFrame:GetChildren()) do
		if v.Name == "Hotbar1" or "Hotbar2" or "Hotbar3" or "Hotbar4" or "Hotbar5" or "Hotbar7" then
			v:SetAttribute("Equipped", false)
			print("Setted.")
		end
	end
	if player.Character:FindFirstChildWhichIsA("Tool") or player.Backpack:FindFirstChildWhichIsA("Tool") then
		local Tool = player.Character:FindFirstChildWhichIsA("Tool") or player.Backpack:FindFirstChildWhichIsA("Tool")
		Tool.Parent = player.Inventory
	end
	h1:SetAttribute("Equipped", true)
	print("Setted.")
	local Tool = player.Inventory:FindFirstChild(h1:GetAttribute("Item"))
	Tool.Parent = player.Character
end

function module:EventTrue(player, Input)
	print(player)
	local GUI2 = player.PlayerGui.HotbarFrame
	local HotbarFrame = GUI2.HotbarFrame
	local h1 = HotbarFrame.Hotbar1
	local h2 = HotbarFrame.Hotbar2
	local h3 = HotbarFrame.Hotbar3
	local h4 = HotbarFrame.Hotbar4
	local h5 = HotbarFrame.Hotbar5
	local h6 = HotbarFrame.Hotbar6
	local h7 = HotbarFrame.Hotbar7
	
	for i, v in pairs(HotbarFrame:GetChildren()) do
		if v.Name == "Hotbar1" or "Hotbar2" or "Hotbar3" or "Hotbar4" or "Hotbar5" or "Hotbar7" then
			v:SetAttribute("Equipped", false)
		end
	end
	if player.Character:FindFirstChildWhichIsA("Tool") or player.Backpack:FindFirstChildWhichIsA("Tool") then
		local Tool = player.Character:FindFirstChildWhichIsA("Tool") or player.Backpack:FindFirstChildWhichIsA("Tool")
		Tool.Parent = player.Inventory
	end
end

return module

Thanks in advance!

Maybe try leaving the functions as module. in the module script instead of module:

3 Likes

Yeah;l;l;l;l;l;l;l;l;l;l;l;l;l;l;l

1 Like

: is used for methods for OOP, you don’t need it for this case and it’s what’s causing “player” to not be sent as the first argument, so just have all your functions use ., eg: function module.EventNone(player, Input)

1 Like

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