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!