This works in studio but not ingame, ingame "Part" returns nil. Part is defined as the object the ray has touched.
local remotes = game:GetService("ReplicatedStorage"):WaitForChild("Remotes")
local tool = script.Parent
local player = game:GetService("Players").LocalPlayer
local ignoreList = {player.Character, unpack(tool:GetChildren())}
tool.Equipped:connect(function(mouse)
mouse.Icon = "rbxassetid://251138645"
mouse.Button1Down:connect(function()
local ray = Ray.new(tool.Handle.CFrame.p, (mouse.Hit.p - tool.Handle.CFrame.p).unit * 300)
local part, position = workspace:FindPartOnRayWithIgnoreList(ray, ignoreList)
local beam = Instance.new("Part")
beam.BrickColor = BrickColor.new("Institutional white")
beam.FormFactor = "Custom"
beam.Material = Enum.Material.SmoothPlastic
beam.Transparency = 0.25
beam.Anchored = true
beam.Locked = true
beam.CanCollide = false
local distance = (tool.Handle.CFrame.p - position).magnitude
beam.Size = Vector3.new(0.3, 0.3, distance)
beam.CFrame = CFrame.new(tool.Handle.CFrame.p, position) * CFrame.new(0, 0, -distance / 2)
beam.Parent = workspace
remotes['RayReplication']:FireServer(beam.Size, beam.BrickColor, beam.CFrame, beam.Material)
table.insert(ignoreList, beam)
delay(0.4, function()
table.remove(ignoreList, 3)
beam:Destroy()
end)
spawn(function()
game:GetService("RunService").Heartbeat:Connect(function()
beam.Size = Vector3.new(beam.Size.X - 0.01, beam.Size.Y - 0.01, beam.Size.Z)
beam.Transparency = beam.Transparency + 0.05
end)
end)
print(part)
if part then print'oof'
local humanoid = part.Parent:FindFirstChild("Humanoid")
if not humanoid then
humanoid = part.Parent.Parent:FindFirstChild("Humanoid")
end
if humanoid then
mouse.Icon = "rbxassetid://253263084"
delay(0.2, function()
mouse.Icon = "rbxassetid://251138645"
end)
remotes['Damage']:FireServer(humanoid)
script.Hit:Play()
end
end
end)
end)
