Hi! I’m working with Raycasts, and lots of the time my script is printing “no raycastresult??”. I’m unsure as to why, as my mouse is on a part, and my character is ignored. There seems to be no consistency as to when RaycastResult fails.
When RaycastResult is returned, the function works perfectly. MouseHit is just Mouse.Hit.p.
Here's my code:
function Shoot(MouseHit)
local Params = RaycastParams.new()
local FromPosition = BodyAttach.Position
print(MouseHit)
local ToPosition = MouseHit
local Direction = ToPosition - FromPosition
Params.FilterDescendantsInstances = {Character}
Params.FilterType = Enum.RaycastFilterType.Blacklist
local RaycastResult = workspace:Raycast(FromPosition, Direction, Params)
if RaycastResult then
local StartAttachment, EndAttachment = Instance.new('Attachment', workspace.Beams), Instance.new('Attachment', workspace.Beams)
StartAttachment.WorldPosition = BodyAttach.Position
EndAttachment.WorldPosition = RaycastResult.Position
local Beam = script.BowBeam:Clone()
Beam.Attachment0 = StartAttachment
Beam.Attachment1 = EndAttachment
Beam.Parent = workspace.Beams
Beam.Enabled = true
else
print('no raycastresult??')
end
end
Event.OnServerEvent:Connect(function(PlayerSent, Action, ...)
if PlayerSent == Player then
if Action == 'PlaySound' and Lib.RemoteFloodCheck(Player, 'Write', Event, Action, 20) then
PlaySound(...)
elseif Action == 'Fire' and Lib.RemoteFloodCheck(Player, 'Write', Event, Action, 10) then
Shoot(...)
end
end
end)
Client
Tool.Equipped:Connect(function(Mouse)
Equipped = true
Lib.ToolAttach('Attach', BodyAttach, Character.HumanoidRootPart)
Animations['Hold']:Play()
table.insert(Connections, Mouse.Button1Down:Connect(function()
MouseUp = false
Animations['Hold']:Stop()
Animations['Reload']:Play()
Event:FireServer('PlaySound', 'Reload', true)
Animations['Reload'].Stopped:Wait()
if Equipped and not MouseUp then
Animations['Draw']:Play()
Event:FireServer('PlaySound', 'Draw', true)
Animations['Draw'].Stopped:Wait()
if Equipped and not MouseUp then
Animations['Aim']:Play()
ReadyToFire = true
end
end
end))
table.insert(Connections, Mouse.Button1Up:Connect(function()
MouseUp = true
Animations['Reload']:Stop()
Animations['Draw']:Stop()
Animations['Aim']:Stop()
Event:FireServer('PlaySound', 'Reload', false)
Event:FireServer('PlaySound', 'Draw', false)
if ReadyToFire then
ReadyToFire = false
Tool.Arrow.Transparency = 1
Animations['Release']:Play()
Event:FireServer('PlaySound', 'Shoot', true)
Animations['Release'].Stopped:Wait()
if Equipped then
Tool.Arrow.Transparency = 0
Event:FireServer('Fire', Mouse.Hit.p) -- <-- Here's what you're looking for
end
end
Animations['Hold']:Play()
end))
end)
local character = game.Players.LocalPlayer.Character
function raycast(origin,endpos,distance)
local ray = Ray.new(origin,(origin-endpos).Unit*Distance)
local hit,pos,norm = workspace:FindPartOnRay(ray,character)
if hit then
print(hit.Name)
else
print('no hit')
end
end
Hm alright ill try using Raycast function then well
local Head = game.Players.LocalPlayer.Head
local Params = RaycastParams.new()
workspace:Raycast(Head.Position,(Head.Position - MouseHit).Unit*1000,Params)
if it doesnt work idk im new to that function aswell LOL