Hi! I made a Laser Gun using Roblox’s Tutorial and I want to make it FE compatible. Any help on how I would go about it?
Local Script:
01 | local tool = script.Parent |
02 | local player = game:GetService( "Players" ).LocalPlayer |
03 | local mouse = player:GetMouse() |
04 | local canPlay = true |
05 | local mouseDown = false |
06 | Equipped = false |
07 | tool.Equipped:Connect( function () |
08 | Equipped = true |
09 | mouse.Button 1 Down:Connect( function () |
10 | mouseDown = true |
11 | end ) |
12 | mouse.Button 1 Up:Connect( function () |
13 | mouseDown = false |
14 | end ) |
15 | while true do |
16 | if mouseDown then |
17 | if canPlay and Equipped then |
18 | canPlay = false |
19 | local ray = Ray.new(tool.Handle.CFrame.p, (mouse.Hit.p - tool.Handle.CFrame.p).unit * 100 ) |
20 | local part, position = workspace:FindPartOnRay(ray, player.Character, false , true ) |
21 | local beam = Instance.new( "Part" , workspace) |
22 | beam.BrickColor = BrickColor.new( "Toothpaste" ) |
23 | beam.FormFactor = "Custom" |
24 | beam.Material = "Neon" |
25 | beam.Transparency = 0.6 |
26 | beam.Anchored = true |
27 | beam.Locked = true |
28 | beam.CanCollide = false |
29 | local distance = (tool.Handle.CFrame.p - position).magnitude |
30 | beam.Size = Vector 3. new( 0.3 , 0.3 , distance) |
31 | beam.CFrame = CFrame.new(tool.Handle.CFrame.p, position) * CFrame.new( 0 , 0 , -distance / 2 ) |
32 | game:GetService( "Debris" ):AddItem(beam, . 01 ) |
33 | if part then |
34 | local humanoid = part.Parent:FindFirstChild( "Humanoid" ) |
35 | if not humanoid then |
36 | humanoid = part.Parent.Parent:FindFirstChild( "Humanoid" ) |
37 | end |
38 | if humanoid then |
39 | humanoid:TakeDamage( 5 ) |
40 | end |
41 | end |
42 | canPlay = true |
43 | end |
44 | end |
45 | wait(. 1 ) |
46 | end |
47 | end ) |
48 | tool.Unequipped:Connect( function () |
49 | Equipped = false |
50 | end ) |
Fire an event which talks to a server script inside the tool and which then the server script does the raycasting. Raycasting or any other modification to existing parts or making new ones cannot be done with LocalScripts because of FilteringEnabled.