I’m using one local script to handle all the tools in my game. However, I’m not sure if it is very effective and it is somewhat buggy.
My question is should I use one local script to handle all the tools in my game. Or use a local script for each and every tool (under the tool itself)? Would it cause performance issues on the client?
Well I’m using one Local script and one server script for all tools because a friend of mine told me to minimize scripts as much as possible But I’m not sure if I am doing it correctly.
Here are the scripts if you are curious:
local script:
local Player = game.Players.LocalPlayer
Player.CharacterAdded:Wait()
local UserInputService = game:GetService("UserInputService")
local ToolRemoteEvent = game:GetService("ReplicatedStorage").RemoteEvents:WaitForChild("ToolsActionRemoteEvent")
local CooldownUI = Player.PlayerGui:WaitForChild("BackPackUI").CooldownText
local ItemDataModule = require(game:GetService("ReplicatedStorage").ModuleScripts.ItemDataModule)
local SoundService = game:GetService("SoundService")
local TweenService = game:GetService("TweenService")
local Tweeninfo = TweenInfo.new(0.3,Enum.EasingStyle.Linear)
local OpenTween = TweenService:Create(CooldownUI,Tweeninfo,{TextTransparency = 0})
local CloseTween = TweenService:Create(CooldownUI,Tweeninfo,{TextTransparency = 1})
local function ToolActivationFunction(Input,active)
if (Input.UserInputType == Enum.UserInputType.MouseButton1 or Input.UserInputType == Enum.UserInputType.Touch) and not active then
local Character = Player.Character
local Tool = Character:FindFirstChildWhichIsA("Tool")
local Mouse = Player:GetMouse()
if Tool then
local ToolInback = Player.Backpack:FindFirstChild(Tool.Name)
if ToolInback.Enabled == true then
ToolInback.Enabled = false
if ItemDataModule.ItemOrintaion[ItemDataModule.ItemList[Tool.Name].Type].AnimationID then
local ItemData = ItemDataModule.ItemOrintaion[ItemDataModule.ItemList[Tool.Name].Type]
local Animation = Instance.new("Animation")
Animation.AnimationId = "rbxassetid://"..ItemData.AnimationID
local Animator = Character.Humanoid:WaitForChild("Animator")
local PlayAnim = Animator:LoadAnimation(Animation)
PlayAnim:Play()
task.wait(0.5)
local Sound = Instance.new("Sound")
Sound.SoundId = "rbxassetid://894160027"
SoundService:PlayLocalSound(Sound)
task.wait(ItemData.AnimationTime - 0.5)
PlayAnim:Stop()
Animation:Destroy()
end
ToolRemoteEvent:FireServer(Tool.Name,Mouse.Target,Mouse.Hit.Position)
else
OpenTween:Play()
OpenTween.Completed:Wait()
CloseTween:Play()
CloseTween.Completed:Wait()
end
end
end
end
UserInputService.InputEnded:Connect(ToolActivationFunction)