Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why won't the beam spawn when I click?


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?

7 comments

0

do you have FE enabled?

0

why do you have 2 things defining the players mouse?

0

Do I?

0

the answer is very simple, you didnt set the parent of the beam.

0

O yeah

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

0

beam.Parent = game.Workspace -- Example of setting a parent for instance

1 answer

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

2 comments

0

or script.Parent but yeah that will work too

0

he didnt say if the local script is in the tool so idk

This discussion is preserved as it was. New answers, comments, and votes are closed.