Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Is it possible to make this serverscript work for many tools and not be messy? [Solved]

I have a localscript inside a tool that communicates with a serverscript with a remote function. Everything works fine, but the only problem is that if its a different tool with the same scripts and stuff but with a different name, I would have to make an entire new serverscript that is the exact same but just for that new tool only or to make a very long serverscript. Is there a way to make it so I can address all of those tools in one script without having to make it very long? (if that made sense)

So if I had 10 tools that had different names with the same exact scripts but modified slightly to fit the name, I would have to have 10 different serverscripts of 1 long serverscript

The local script

local plr = game.Players.LocalPlayer
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Attack = ReplicatedStorage:WaitForChild("OnAttackSword")
local char = plr.Character
local Tool = script.Parent

Tool.Activated:Connect(function()

	if Tool.Handle.Cooldown.Value == false then 
		Tool.Handle.Cooldown.Value = true
		print(plr.Name.. "Stone Sword was Activated")
		game.ReplicatedStorage:FindFirstChild("OnAttackSword"):FireServer(char, Tool)
		local animation = plr.Character.Humanoid:LoadAnimation(script.Parent.Attack1)
		animation:Play()
		wait(1.2) 
		print(plr.Name.. "Stone Sword Recharged")
		Tool.Handle.Cooldown.Value = false
	end

end)

Tool.Unequipped:Connect(function() 
	print(plr.Name.. "Unequipped Stone Sword")
	Tool.Damage.Disabled = true
end)

The serverscript

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Attack = ReplicatedStorage:WaitForChild("OnAttackSword")

game.ReplicatedStorage.OnAttackSword.OnServerEvent:Connect(function(player,char,Tool)
	
	print("Remote Event OnAttackSword Fired")
	char.Humanoid.WalkSpeed = 0
	char.Humanoid.JumpPower = 0
	char.StoneSword.Damage.Disabled = false
	wait(0.7)
	char.Humanoid.WalkSpeed = 20
	char.Humanoid.JumpPower = 50
	char.StoneSword.Damage.Disabled = true
	
	
end)

1 answer

This discussion is preserved as it was. New answers, comments, and votes are closed.