Need help how to using laser attachment for tool

  1. What do you want to achieve?
    I want a laser attachment like the type of model is a part of the tool it works when using the tool, not a model to look it for fun, pls :pleading_face: :pleading_face:
  2. What is the issue?
    I want the model laser it working inside the tool certain, not the model in the workspace.
  3. What solutions have you tried so far?
    I was edit a bit but I don’t much about this so only edit it a bit then I paste it on the tool but not working, I want it to work for players to aiming and shoot better than
    Model(Target)
    Screenshot (1509)
    here is script 1(Normal script)
local lt = script.Parent
local part = lt.laserend
local part1 = lt.Part1

local player = game:GetService("Players").LocalPlayer
local TweenService = game:GetService("TweenService")

local ray_part = lt.Ray



local sentry = workspace.Glock.LaserSentry


local ray_start = part1.Position  --Where the ray starts.
local head = script.Parent.head.Value
local ray_end = head.Position



local dot = lt.dot

local db = 0

--[[function touched(hit)

dot.Transparency = 0
part.Beam.Transparency = NumberSequence.new(0)
	end
	
function touchstop()
	
dot.Transparency = 1
part.Beam.Transparency = NumberSequence.new(1)

end

ray_part.Touched:Connect(touched)
ray_part.TouchEnded:Connect(touchstop)]]

function touching()
		local ray = Ray.new(ray_start, ray_end - ray_start)  --Subtracting ray_start from ray_end is needed because of the way FindPartOnRay() works.
	local part_hit, hit_position, normal = game.Workspace:FindPartOnRay(ray, dot)
	
	
	
	--This is the tricky math part.
	local length = (ray_start - hit_position).magnitude
	local z_amount = length/2
	--
	ray_part.Size = Vector3.new(0.05, 0.15, length)
	--Then the tricky CFrame part.

ray_part.CFrame = CFrame.new(ray_start, hit_position) * CFrame.new(0, 0, -z_amount)  --The first CFrame command moves the ray to the torso and rotates it to face towards hit_position.  The second CFrame command moves it forward half its length so that actually makes a line inbetween the torso's position and hit_position, instead of going half way in both directions.
	dot.CFrame = CFrame.new(hit_position, hit_position + normal)
	wait()

end

while wait() do
	touching()
end

And script 2(Local script)[Disabled]

local lt = script.Parent
local part = lt.laserend
local part1 = lt.Part1

local player = game:GetService("Players").LocalPlayer
local TweenService = game:GetService("TweenService")

local ray_part = lt.Ray

local ray_start = part1.Position  --Where the ray starts.
local ray_end = part.Position --Where the ray ends.

--local attach = part.Attachment

local dot = lt.dot

local db = 0

function touched(hit)

--[[dot.Transparency = 0
part.Beam.Transparency = NumberSequence.new(0)]]
	end
	
function touchstop()
	
--[[dot.Transparency = 1
part.Beam.Transparency = NumberSequence.new(1)]]

end

ray_part.Touched:Connect(touched)
ray_part.TouchEnded:Connect(touchstop)

function touching()
	--part.Size = Vector3.new(0.45, 0.55, 0.55)
	
		local ray = Ray.new(ray_start, ray_end - ray_start)  --Subtracting ray_start from ray_end is needed because of the way FindPartOnRay() works.
	local part_hit, hit_position, normal = game.Workspace:FindPartOnRay(ray, dot)
	
	
	
	--This is the tricky math part.
	local length = (ray_start - hit_position).magnitude
	local z_amount = length/2
	--
	ray_part.Size = Vector3.new(0.05, 0.15, length)
	--Then the tricky CFrame part.

ray_part.CFrame = CFrame.new(ray_start, hit_position) * CFrame.new(0, 0, -z_amount)  --The first CFrame command moves the ray to the torso and rotates it to face towards hit_position.  The second CFrame command moves it forward half its length so that actually makes a line inbetween the torso's position and hit_position, instead of going half way in both directions.
	dot.CFrame = CFrame.new(hit_position, hit_position + normal)
	wait()
	--ray_part:remove()
end


while wait() do
	touching()
end
1 Like

send me a place file please so I can look at it

Sorry for not fixing the previous issues that you said. Because I was too busy

2 Likes

I was added you on my map, name it very easy to find, name is “Fix it help me” :slightly_smiling_face:
@thebrickplanetboy Chat with me through discord, fjdjdjdjejdj_lol#7431 to talk how it’s bug

1 Like

@thebrickplanetboy Can you help me this please, I want it working as keybind + button support mobile

local button = script.Parent
local nvgscreen = button.Parent.ImageLabel
local toggled = false
local nvgsound = workspace.NightVisionSound

local function onButtonActivated()
	print("button pressed")
	if toggled == false then
		local cc = game.Lighting.ColorCorrection2
		cc.Enabled = true
		nvgsound:Play()
		game.Lighting.ColorCorrection2.Contrast = -1
		wait(0.5)
		game.Lighting.ColorCorrection2.Contrast = -0.9
		wait(0.05)
		game.Lighting.ColorCorrection2.Contrast = -0.8
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = -0.7
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = -0.6
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = -0.5
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = -0.4
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = -0.3
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = -0.2
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = -0.1
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = 0
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = 0.1
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = 0.2
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = 0.3
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = 0.4
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = 0.5
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = 0.6
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = 0.7
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = 0.8
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = 0.9
		wait(0.01)
		game.Lighting.ColorCorrection2.Contrast = 1
		wait(0.01)
		toggled = true
	else
		local cc = game.Lighting.ColorCorrection2
		game.Lighting.ColorCorrection2.Contrast = -0.7
		wait(0.1)
		game.Lighting.ColorCorrection2.Contrast = -0.8
		wait(0.05)
		game.Lighting.ColorCorrection2.Contrast = -0.9
		wait(0.03)
		game.Lighting.ColorCorrection2.Contrast = -1
		wait(0.01)
		cc.Enabled = false
		toggled = false
	end
end
button.Activated:Connect(onButtonActivated)