File size: 1,461 Bytes
0712d5f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
-- 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)