Should I use one local script for all my tools?

Hello everyone,

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?

1 Like

Its Better to have a Server Script and a Local Script for the Tool

My Reason:

  • ServerScript
    Use it to make calculations and setup RemoteEvents

  • LocalScript
    Use to Fire RemoteEvents

An Example of this is a Firearm


I don’t think so unless you are firing too much

However you can Use 1 Script form all Tools to Fire a RemoteEvent and Fire it within a LocalScript inside the Tool

Sorry if this is a little off topic

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)

It depends, if you want to Apply a certain Attribute to a Specific Class, its Valid, but if you have a Weapon with Different Attributes

You either Apply those attributes to the Script or have a Separate script inside the tool to run it

Well all attributes of the tools are saved in a Server module script so the local script has nothing to worry about.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.