How would I make this local script into a script?

I was following a tutorial on how to make a gun, but then I released that in the tutorial the gun was made in a local script, and so was the damage, so it wouldn’t actually damage other players. It wouldn’t work when I made it into a normal script. I’m confused because I know I can probably make an event that damages players but I don’t know how I would do that.
This is the local script

local plr = game.Players.LocalPlayer
local tool = script.Parent.Parent
local hole = tool:WaitForChild("Hole")
local handle = tool.Handle
local debounce = true
local config = tool.Config
local range = config.Range
local dmg = config.Damage
local coolDown = config.CoolDown
local clips = config.Clips
local ammo = config.Ammo
local maxAmmo = config.MaxAmmo
local allowTracing = config.AllowTracing
local reloadTime = config.ReloadTime
local isReloading = false
local mouseDown = false
--//Sounds
local reloadSound = tool.Handle.ReloadSound
local fireSound = tool.Handle.FireSound
local equipSound = tool.Handle.EquipSound
local emptySound = tool.Handle.EmptySound
--//Animations
repeat wait() until plr.Character.Humanoid
local AnimFolder = script.Parent.Parent:WaitForChild("Animations")
local ReloadTrack = plr.Character.Humanoid:LoadAnimation(AnimFolder:WaitForChild("PistolReload"))
local AimTrack = plr.Character.Humanoid:LoadAnimation(AnimFolder:WaitForChild("PistolAim"))
local HoldTrack = plr.Character.Humanoid:LoadAnimation(AnimFolder:WaitForChild("PistolHold"))
local ShootTrack = plr.Character.Humanoid:LoadAnimation(AnimFolder:WaitForChild("PistolShoot"))
AimTrack.Looped = true
HoldTrack.Looped = true
 
--//Events
tool.Equipped:connect(function(mouse)
    equipSound:Play()
    HoldTrack:Play()
 
    mouse.KeyDown:connect(function(Key)
        if Key:lower() == "q" then
            workspace.CurrentCamera.FieldOfView = 60
            AimTrack:Play()
        end
    end)
   
    mouse.KeyUp:connect(function(Key)
        if Key:lower() == "q" then
            workspace.CurrentCamera.FieldOfView = 70
            AimTrack:Stop()
        end
    end)
   
    mouse.Button1Up:connect(function()
        mouseDown = false
    end)
   
mouse.Button1Down:connect(function()
	   wait()
        mouseDown = true
        repeat
		if debounce then
			  wait()
                Shoot()
            else
                break
            end
        until mouseDown == false
    end)
   
    --//Reload Event
mouse.KeyDown:connect(function(key)
	wait()	
	if key:lower() == "r" then
		wait()
		 if not isReloading then
			wait()
			 if clips.Value > 0 then
				wait()
                    ReloadTrack:Play()
                    reloadSound:Play()
                    isReloading = true
                    ammo.Value = maxAmmo.Value
                    clips.Value = clips.Value - 1
                    debounce = false
                    wait(reloadTime.Value)
                    isReloading = false
                    debounce = true
                end
            end
        end
    end)
   
    function Shoot()
	if not isReloading then
		wait()	
		if ammo.Value > 0 then
			wait()	
                if debounce then
				--//Play sound
				wait()	
				ShootTrack:Play()
                    fireSound:Play()
                    --//Doesn't allow spamming
                    debounce = false
                    --//Ray Get, Set
                    local ray = Ray.new(hole.CFrame.p, (mouse.Hit.p - hole.CFrame.p) * range.Value)
                    local hit, position = workspace:FindPartOnRay(ray, plr.Character, false, true)
                   
                    --//Bullet Tracing
                    if allowTracing.Value == true then
					--//Make part
				    wait()	
                        local trace = Instance.new("Part", workspace)
                        trace.Material = Enum.Material.Neon
                        trace.BrickColor = BrickColor.new("Black")
                        trace.CanCollide = false
                        trace.Anchored = true
                        trace.Transparency = 0.5
                       
                        --//Show Direction
                        local distance = (hole.CFrame.p - position).magnitude
                        trace.Size = Vector3.new(0.2, 0.2, distance)
                        trace.CFrame = CFrame.new(hole.CFrame.p, position) * CFrame.new(0, 0, -distance/2)
                       
                        --//Remove debris
                        game:GetService("Debris"):AddItem(trace, 0.1)
                    end
                           
                    --//Hit Detection
				if hit then
					wait()	
                        local humanoid =  hit.Parent:FindFirstChild("Humanoid")
                        if humanoid then
                            if hit.Name == "Head" then
                                --//Double damage on headshots
                                humanoid:TakeDamage(dmg.Value*2)
                            else
                                --//Normal Damage on body shots
                                humanoid:TakeDamage(dmg.Value)
                            end
                        end
                    end
                    wait(coolDown.Value)
                    ammo.Value = ammo.Value - 1
                    debounce = true
                end
            else
	--//Out of ammo
			 wait()
                emptySound:Play()
            end
        end    
    end
end)
 
tool.Unequipped:connect(function()
    wait()	
    mouseDown = false
    AimTrack:Stop()
    HoldTrack:Stop()
    ReloadTrack:Stop()
end)
1 Like

For starters you should move the raycasting+damaging logic in the shoot method to something that is ran server-side using a remote event. It might be a bit difficult if you are new to scripting, but its definately something you can learn a ton from.

2 Likes

If you change the RunContext of your LocalScript to Server, then it will literally turn your LocalScript into a normal/server Script.
Screenshot_20221113_112035
This feature was added a few months ago.