Hey i’m DevFoll and i wanna create a gun that requires raycasting i’ve created the raycast and i wanna add an effect like this
https://cdn.discordapp.com/attachments/938894648062124033/938992419763011614/2022-02-03_21-59-34.mp4 But i don’t know how to create that i almost did it but not complety good, I don’t have the best understanding in raycasting so i came here to ask you guys
Video file was to big so had to get the link, clicking the link will install the video i tested
This is my server code:
**script.Parent.RemoteEvent.OnServerEvent:Connect(function(Player, MousePos, MouseCFrame)
local Anim = Player.Character:FindFirstChild("Humanoid"):LoadAnimation(script.Parent.Animations.Shooting)
local Params = RaycastParams.new()
Params.FilterDescendantsInstances = {Player.Character}
Params.FilterType = Enum.RaycastFilterType.Blacklist
local Raycast = game.Workspace:Raycast(script.Parent.Part.Position,( MousePos - script.Parent.Part.Position)*300, Params)
if Raycast then
local CharHit = Raycast.Instance:FindFirstAncestorOfClass("Model")
local Smoke = game.ReplicatedStorage.Smoke:Clone()
local Particle = game.ReplicatedStorage.ParticleEmitter:Clone()
Particle.Parent = script.Parent.Part
Smoke.Parent = script.Parent.Part
script.Parent.Part.PointLight.Enabled = true
script.Parent.Ammo.Value -= 1
script.Parent.Handle.fire:Play()
Anim:Play()
local Bullet = game.ReplicatedStorage.Bullet:Clone()
print(MousePos)
wait(0.3)
script.Parent.Part.PointLight.Enabled = false
Particle:Destroy()
Anim:Stop()
local s,e = pcall(function()
if (MousePos - script.Parent.Part.Position).Magnitude < 30 then
if Raycast.Instance.Name == "Head" and CharHit:FindFirstChild("Humanoid") then
CharHit.Humanoid.Health = 0
elseif CharHit:FindFirstChild("Humanoid") then
CharHit.Humanoid.Health -= 50
end
end
end)
wait(0.8)
Smoke:Destroy()
end
end)**
And this is my client code: **local Mouse = game.Players.LocalPlayer:GetMouse()
local Debounce = false
local UIS = game:GetService("UserInputService")
script.Parent.Activated:Connect(function()
if Debounce == false and script.Parent.Ammo.Value > 0 then
Debounce = true
script.Parent.RemoteEvent:FireServer(Mouse.Hit.Position, Mouse.Hit)
wait(1.2)
Debounce = false
elseif Debounce == false and script.Parent.Ammo.Value <= 0 then
script.Parent.NeedsAmmo:FireServer()
end
end)
UIS.InputBegan:Connect(function(Input)
if Input.KeyCode == Enum.KeyCode.R and script.Parent.Parent == game.Players.LocalPlayer.Character then
script.Parent.Reload:FireServer()
end
end)
UIS.InputBegan:Connect(function(Input)
if Input.KeyCode == Enum.KeyCode.LeftShift and game.Players.LocalPlayer.Character.Humanoid.WalkSpeed < 24 then
game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 24
elseif Input.KeyCode == Enum.KeyCode.LeftShift and game.Players.LocalPlayer.Character.Humanoid.WalkSpeed >= 24 then
game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 16
end
end)**
``` In short i wanna make a part that has the size of 0.3 square and is long enough to show from the handle of the gun to the endmousepos.