local mouse = game.Players.LocalPlayer:GetMouse()
mouse.Button1Down:Connect(function()
script.Parent.GunEvent:FireServer(mouse.Hit.p)
end)
Server script:
local tool = script.Parent
local handle = tool.Handle
local enabled = true
local shotSFX = handle.Shot
local shotEffect = handle.Attachment.ParticleEmitter
local shotLight = handle.Attachment.PointLight
tool.Activated:Connect(function()
if not enabled then return end
enabled = false
shotSFX:Play()
shotEffect.Enabled = true
shotLight.Enabled = true
wait(0.1)
shotLight.Enabled = false
shotEffect.Enabled = false
wait(0.2)
enabled = true
end)
tool.GunEvent.OnServerEvent:Connect(function(player, mousePos)
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {player.Character}
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
local raycastResult = workspace:Raycast(script.Parent.Handle.Position, (mousePos - script.Parent.Handle.Position*300),raycastParams)
if raycastResult then
local hitPart = raycastResult.Instance
local model = hitPart:FindFirstAncestorOfClass("Model")
if model then
if model:FindFirstChild("Humanoid") then
model.Humanoid.Health -= 30
end
end
end
end)
tool.GunEvent.OnServerEvent:Connect(function(player, mousePos)
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {player.Character}
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
local origin = script.Parent.Handle.Position
local direction = (mousePos - origin).Unit
local raycastResult = workspace:Raycast(origin,direction * 300,raycastParams)
if raycastResult then
local hitPart = raycastResult.Instance
local model = hitPart:FindFirstAncestorOfClass("Model")
local hum = model:FindFirstChildOfClass("Humanoid")
if model and model.Name ~= player.Name and hum then
hum:TakeDamage(30)
end
end
end)