IS there a better way to write this so it’s neater and easier to read / more secure etc?
The idea is it takes the player and a ‘actionContext’ which is a string either M1 or M2 then determines what tool you have and which function to fire / with what information.
game.ReplicatedStorage.Events._useTool.OnServerEvent:Connect(function(player, actionContext)
-- Determine what the 'player' is trying to do here.
local character = player.Character
local selectedTool
-- first lets determine what tool you're trying to use :)
if character:FindFirstChildOfClass('Tool') then
selectedTool = character:FindFirstChildOfClass('Tool')
else
--// PUNCH LOGIC \\--
if actionContext == 'M1' then
combatModule.MouseButton1_Attack()
end
if actionContext == 'M2' then
combatModule.MouseButton2_Attack()
end
end
if selectedTool then
-- determine what to do!! :)
if selectedTool:GetAttribute('toolType') == 'weapon' then
if actionContext == 'M1' then
combatModule.MouseButton1_Attack()
end
if actionContext == 'M2' then
combatModule.MouseButton2_Attack()
end
end
if selectedTool:GetAttribute('toolType') == 'ability' and actionContext == 'M1' then
warn('no logic for abilities yet :( come back later')
end
if selectedTool:GetAttribute('toolType') == 'food' then
warn('no logic for food!')
end
if selectedTool:GetAttribute('toolType') == 'potion' then
warn('no logic for potions either!')
end
if selectedTool:GetAttribute('toolType') == 'artifact' then
warn('no logic for artifiacts yet c:')
end
-- more logic here
end
end)