-
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 -
What is the issue?
I want the model laser it working inside the tool certain, not the model in the workspace. -
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)
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