Answered by
6 years ago Edited 6 years ago
First create a RemoteEvent in your gun and name it FireEvent
Second create a normal script (not a local script) in your gun
Third change your local script to this
1 | mouse.Button 1 Down:connect( function () |
2 | local ray = Ray.new(hole.CFrame.p, (mouse.Hit.p - hole.CFrame.p).unit * 300 ) |
3 | local part, position = game.Workspace:FindPartOnRay(ray, player.Character, false , true ) |
4 | script.Parent:WaitForChild( "FireEvent" ):FireServer(part, position) |
Finally copy and paste this into your normal script
01 | script.Parent:WaitForChild( "FireEvent" ).OnServerEvent:connect( function (player, part, position) |
02 | local beam = Instance.new( "Part" , game.Workspace) |
03 | beam.BrickColor = BrickColor.new( "Bright red" ) |
04 | beam.FormFactor = "Custom" |
05 | beam.Material = "Neon" |
06 | beam.Transparency = 0.5 |
09 | beam.CanCollide = false |
11 | local distance = (hole.CFrame.p - position).magnitude |
12 | beam.Size = Vector 3. new( 0.3 , 0.3 , distance) |
13 | beam.CFrame = CFrame.new(hole.CFrame.p, position) * CFrame.new( 0 , 0 , -distance / 2 ) |
15 | game:GetService( "Debris" ):AddItem(beam, 0.1 ) |
18 | local humanoid = part.Parent:FindFirstChild( "Humanoid" ) |
20 | humanoid = part.Parent.Parent:FindFirstChild( "Humanoid" ) |
24 | print ( "hit " ..part.Name) |
26 | humanoid:TakeDamage(damage) |
Closed as Not Constructive by valchip and User#19524
This question has been closed because it is not constructive to others or the asker. Most commonly, questions that are requests with no attempt from the asker to solve their problem will fall into this category.
Why was this question closed?