TimberWoods / src /ServerScriptService /InventoryManager.server.lua
algorembrant's picture
Upload 88 files
0712d5f verified
-- src/ServerScriptService/InventoryManager.server.lua
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ShopConfig = require(ReplicatedStorage:WaitForChild("Shared"):WaitForChild("ShopConfig"))
local ChoppingConfig = require(ReplicatedStorage:WaitForChild("Shared"):WaitForChild("ChoppingConfig"))
local EquipToolEvent = ReplicatedStorage:WaitForChild("Events"):WaitForChild("EquipToolEvent")
local NotificationEvent = ReplicatedStorage:WaitForChild("Events"):WaitForChild("NotificationEvent")
-- Handle equip tool requests from client
local function onEquipTool(player, toolId)
if not toolId or type(toolId) ~= "string" then return end
-- Validate the tool exists in configs
if not ChoppingConfig.AxeTypes[toolId] then return end
-- Validate the player owns the tool
if not _G.HasInInventory(player, "Tools", toolId) then
NotificationEvent:FireClient(player, "Error", "You don't own this tool!")
return
end
-- Update the equipped axe
local data = _G.GetPlayerData(player)
if data then
data.EquippedAxe = toolId
player:SetAttribute("EquippedAxe", toolId)
-- Update character attribute
local character = player.Character
if character then
character:SetAttribute("EquippedAxe", toolId)
end
NotificationEvent:FireClient(player, "Equipped", "Equipped " .. toolId)
end
end
EquipToolEvent.OnServerEvent:Connect(onEquipTool)