It is ok if its in a different script
local Player = game.Players.LocalPlayer local Mouse = Player:GetMouse() local k = Instance.new("Part") local Tool = script.Parent.Parent local canshoot = false Tool.Equipped:Connect(function() canshoot = true end) Tool.Unequipped:Connect(function() canshoot = false end) Mouse.Button1Down:Connect(function() if canshoot == true then wait(0.5) k.Parent = game.Workspace k.Color = Color3.fromRGB(1,1,1) k.Size = Vector3.new(0.08, 0.08, 0.08) k.Anchored = true k.CanCollide = false k.Position = Vector3.new(Mouse.Hit) k.CFrame = Mouse.Hit script.Parent.Shoot:Play() repeat wait(.001) script.Parent.PointLight.Enabled = true until script.Parent.Shoot.Playing == false if script.Parent.Shoot.Playing == false then script.Parent.PointLight.Enabled = false end end end) function onTouched(hit) local human = hit.Parent:findFirstChild("Humanoid") if (human ~= nil) then human.Health = human.Health - 7 if k.Touched then k:Destroy() end end end k.Touched:connect(onTouched)
remplace the :
local Player = game.Players.LocalPlayer
with :
game.Players.PlayerAdded:Connect(function(player)) -- insert your code here and remplace Player with player end)
--Edited The New Code:
game.Players.PlayerAdded:Connect(function(player) local Mouse = player:GetMouse() local k = Instance.new("Part") local Tool = script.Parent.Parent local canshoot = false Tool.Equipped:Connect(function() canshoot = true end) Tool.Unequipped:Connect(function() canshoot = false end) Mouse.Button1Down:Connect(function() if canshoot == true then wait(0.5) k.Parent = game.Workspace k.Color = Color3.fromRGB(1,1,1) k.Size = Vector3.new(0.08, 0.08, 0.08) k.Anchored = true k.CanCollide = false k.Position = Vector3.new(Mouse.Hit) k.CFrame = Mouse.Hit script.Parent.Shoot:Play() repeat wait(.001) script.Parent.PointLight.Enabled = true until script.Parent.Shoot.Playing == false if script.Parent.Shoot.Playing == false then script.Parent.PointLight.Enabled = false end end end) function onTouched(hit) local human = hit.Parent:findFirstChild("Humanoid") if (human ~= nil) then human.Health = human.Health - 7 if k.Touched then k:Destroy() end end end k.Touched:connect(onTouched) end)