Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
3

Why won't the beam spawn when I click?

Asked by
Synth_o 136
6 years ago
Edited 6 years ago
01local gun = game.StarterPack.Gun1.Handle.CFrame
02local part = game.Workspace.beamtest.CFrame
03local Players = game:GetService("Players")
04local mouse = Players:GetMouse()
05Tool = game.StarterPack.Gun1
06 
07mouse.Button1Down:connect(function()
08    local att0 = Instance.new('Attachment', part)
09    local att1 = Instance.new('Attachment', gun)
10    local beam = Instance.new("Beam")
11    att0.Position = Vector3.new(gun)
12    att1.Position = Vector3.new(part)
13    att0.Parent = workspace.Terrain
14    att1.Parent = workspace.Terrain
15    beam.color = Color3.fromRGB(144,144,144)   
View all 22 lines...

Sorry for the inconvenience about all the questions! Last question probably but why won't a beam appear?

0
do you have FE enabled? Pumpk1n52 22 — 6y
0
why do you have 2 things defining the players mouse? User#23365 30 — 6y
0
Do I? Synth_o 136 — 6y
0
the answer is very simple, you didnt set the parent of the beam. User#23365 30 — 6y
View all comments (3 more)
0
O yeah Pumpk1n52 22 — 6y
0
You never registered the mouse clicking.. You also don't need the mouse in line 7 https://www.robloxdev.com/api-reference/event/Mouse/Button1Down Shawnyg 4330 — 6y
0
beam.Parent = game.Workspace -- Example of setting a parent for instance LoganboyInCO 150 — 6y

1 answer

Log in to vote
1
Answered by 6 years ago
Edited 6 years ago

first of all, you didnt set the Parent of the Beam so it wont appear, and you dont need to set the Position of the beam. also the Equipped event wont fire if the player clicks the mouse, it fires when the tool is equipped by the player the event you want is the Button1Down event of the players mouse such as this example.

1script.Parent.Equipped:Connect(function(mouse)              
2    mouse.Button1Down:Connect(function()
3        print("i have been clicked")
4    end)
5end)

also your defining the player's mouse 2 times in your script as your doing a variable of the mouse and the parameter of the Equipped event which is the players mouse.

01local part = game.Workspace.beamtest
02local Players = game:GetService("Players").LocalPlayer
03local Tool = script.Parent
04local gun = script.Parent.Handle
05 
06Tool.Equipped:Connect(function(mouse) -- :connect() is decaperated, use :Connect()
07    mouse.Button1Down:Connect(function()
08        local att0 = Instance.new('Attachment')
09            local att1 = Instance.new('Attachment')
10        local beam = Instance.new("Beam")
11 
12        beam.Color = Color3.fromRGB(144,144,144)
13        beam.Attachment0 = att0
14            beam.Attachment1 = att1
15 
View all 23 lines...

and the parent arguement of Instance.new() is decaperated, instead set the parent last, and i would also suggest using the players Backpack instead of StarterPack. theres alot more mistakes too

0
or script.Parent but yeah that will work too Vulkarin 581 — 6y
0
he didnt say if the local script is in the tool so idk User#23365 30 — 6y
Ad

Answer this question