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
5 years ago
Edited 5 years ago

local gun = game.StarterPack.Gun1.Handle.CFrame local part = game.Workspace.beamtest.CFrame local Players = game:GetService("Players") local mouse = Players:GetMouse() Tool = game.StarterPack.Gun1 mouse.Button1Down:connect(function() local att0 = Instance.new('Attachment', part) local att1 = Instance.new('Attachment', gun) local beam = Instance.new("Beam") att0.Position = Vector3.new(gun) att1.Position = Vector3.new(part) att0.Parent = workspace.Terrain att1.Parent = workspace.Terrain beam.color = Color3.fromRGB(144,144,144) beam.Attachment0 = att0 beam.Attachment1 = att1 beam.Width0 = 0.2 -- starts small beam.Width1 = 2 -- ends big beam.Enabled = true beam.Parent = att0 end)

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 — 5y
0
why do you have 2 things defining the players mouse? User#23365 30 — 5y
0
Do I? Synth_o 136 — 5y
0
the answer is very simple, you didnt set the parent of the beam. User#23365 30 — 5y
View all comments (3 more)
0
O yeah Pumpk1n52 22 — 5y
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 — 5y
0
beam.Parent = game.Workspace -- Example of setting a parent for instance LoganboyInCO 150 — 5y

1 answer

Log in to vote
1
Answered by 5 years ago
Edited 5 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.

script.Parent.Equipped:Connect(function(mouse)               
    mouse.Button1Down:Connect(function()
        print("i have been clicked")
    end)
end)

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.

local part = game.Workspace.beamtest
local Players = game:GetService("Players").LocalPlayer
local Tool = script.Parent
local gun = script.Parent.Handle

Tool.Equipped:Connect(function(mouse) -- :connect() is decaperated, use :Connect()
    mouse.Button1Down:Connect(function()
        local att0 = Instance.new('Attachment')
            local att1 = Instance.new('Attachment')
        local beam = Instance.new("Beam")

        beam.Color = Color3.fromRGB(144,144,144)
        beam.Attachment0 = att0
            beam.Attachment1 = att1

        beam.Width0 = 0.2 
            beam.Width1 = 2

        att0.Parent = gun
        att1.Parent = part
        beam.Parent = workspace
    end)
end)

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 — 5y
0
he didnt say if the local script is in the tool so idk User#23365 30 — 5y
Ad

Answer this question