Convert Local Script inside tool to a Server-Sided script

  1. What do you want to achieve? Keep it simple and clear!
    I want to convert my Local Script inside my tool into a Server-Sided script so all players can see the tool working.
  2. What is the issue? Include screenshots / videos if possible!
    I put everything from the Local Script into a Normal Script, everything worked fine except for UserInputService. I’m having trouble understanding how to make the KeyCode function work with the Server.
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I’ve done around 45 minutes of research and still can’t understand how to make my second attack show up on the Server.

Here is my script:

-- Locals --

local tool = script.Parent
local UserInputService = game:GetService("UserInputService")
local anim = Instance.new("Animation")
local anim1 = Instance.new("Animation")
local anim2 = Instance.new("Animation")
local anim3 = Instance.new("Animation")
local blade = tool.blade
local bladein = tool.innerblade
local light = blade.PointLight
local light2 = blade.PointLightLarge
local eqpsnd = tool.Handle.Equip
local idlesnd = tool.Handle.Idle
local uneqpsnd = tool.Handle.Unequip
local swngsnd = tool.Handle.Slash
local swngsndbg = tool.Handle.SlashBig
local swngsndsm = tool.Handle.SlashSmall
local trail = tool.innerblade.Trail
local Debounce = false

-- Animation --

anim.Name = "IdleAnim"
anim.AnimationId = "rbxassetid://10164092283"
anim1.Name = "EquipAnim"
anim1.AnimationId = "rbxassetid://10164101710"
anim2.Name = "SlashAnim"
anim2.AnimationId = "rbxassetid://10164095647"
anim3.Name = "SlashBgAnim"
anim3.AnimationId = "rbxassetid://10164099818"
local track
local track1
local track2
local track3

-- Attack --

-- When Tool Equipped
tool.Equipped:Connect(function()
	Debounce = true
	eqpsnd:Play()
	track = script.Parent.Parent.Humanoid:LoadAnimation(anim)
	track1 = script.Parent.Parent.Humanoid:LoadAnimation(anim1)
	track.Priority = Enum.AnimationPriority.Movement
	track1.Priority = Enum.AnimationPriority.Movement
	track.Looped = true
	track:Play()
	track1:AdjustSpeed(0.3)
	track1:Play()
	wait(0.8)
	idlesnd:Play()

	blade.Transparency = 0.1
	bladein.Transparency = 0.2
	light.Enabled = true
	light.Enabled = true
	Debounce = false
end)

-- When Tool UnEquipped
tool.Unequipped:Connect(function()
	if track and track1 then
		idlesnd:Stop()
		blade.Transparency = 1
		bladein.Transparency = 1
		light.Enabled = false
		light.Enabled = false
		uneqpsnd:Play()
		track:Stop()
		track1:Stop()
	end
end)

-- When Tool Activated
tool.Activated:Connect(function()
	if not Debounce then
		Debounce = true
		track2 = script.Parent.Parent.Humanoid:LoadAnimation(anim2)
		track2:Play()
		trail.Enabled = true
		swngsnd:Play()
		wait(0.9)
		trail.Enabled = false
		wait(0.3)
		Debounce = false
	end		
end)

-- 2nd Attack
UserInputService.InputBegan:Connect(function(input, recieved)
	if input.KeyCode == Enum.KeyCode.F then
		if not Debounce then
			Debounce = true
			track3 = script.Parent.Parent.Humanoid:LoadAnimation(anim3)
			track3:Play()
			script.Parent.Parent.Humanoid.WalkSpeed = 0
			trail.Enabled = true
			swngsndbg:Play()
			wait(1.7)
			swngsndsm:Play()
			wait(1)
			trail.Enabled = false
			script.Parent.Parent.Humanoid.WalkSpeed = 25
			Debounce = false	
		end
	end
end)

The UserInputService only works on the client, so you cant do it in a server script.

There are things called RemoteFunctions, they are meant to “convert” things in a LocalScript to the server.
Please read this documentation (the whole thing), it explains how they work and what you have to do.

Basically, in the LocalScript you only write the UIS stuff, and everything else that happens goes into a ServerScript that you call from the LocalScript.