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

Raycast not hitting all the time?

I made a meteor power system for our school project game and i tried using raycasting to make the explosion more accurate but the raycast doesn't seem to hit all the time. Anyways here's the code :

wait(1)
local CanCollide = true
local TweenService = game:GetService("TweenService")
local Debris = game:GetService("Debris")

game.ReplicatedStorage.RenderStepped.OnServerEvent:Connect(function(Player)
	local Raycast = workspace:Raycast((script.Parent.CFrame * CFrame.new(0,0,-4)).Position,(script.Parent.CFrame * CFrame.new(0,0,-25)).Position)
	if (Raycast) and CanCollide == true then
		if Raycast.Instance.CanCollide == true then
			CanCollide = false
			local Explosion = game.ReplicatedStorage.Explosion:Clone()
			Explosion.Parent = workspace.Debris
			Explosion.Anchored = true
			Explosion.CanCollide = false
			Explosion.CFrame = CFrame.new(Raycast.Position,Raycast.Position + Raycast.Normal)
			Explosion.Color = Raycast.Instance.Color
			Explosion.Size = Vector3.new(0,0,0)
			Explosion.Material = "Neon"
			Explosion.CastShadow = false
			local Tween = TweenService:Create(Explosion,TweenInfo.new(2,Enum.EasingStyle.Exponential,Enum.EasingDirection.Out,0,false,0),{Size = Vector3.new(100,100,100)})
			Tween:Play()
			local Tween = TweenService:Create(Explosion,TweenInfo.new(4,Enum.EasingStyle.Quart,Enum.EasingDirection.Out,0,false,0),{Transparency = 1})
			Tween:Play()
			Debris:AddItem(Explosion,3)
			for i = 0,13,1 do
				local Splash = game.ReplicatedStorage.SplashExplosion:Clone()
				Splash.Parent = workspace
				Splash.CFrame = Explosion.CFrame
				Splash.Velocity = (CFrame.new(Raycast.Position,Raycast.Position + Raycast.Normal) * CFrame.new(math.random(-100,100),math.random(-90,100),math.random(-100,100))).Position
				Splash.ParticleEmitter.Color = ColorSequence.new{
					ColorSequenceKeypoint.new(0,Raycast.Instance.Color),
					ColorSequenceKeypoint.new(1,Color3.fromRGB(235, 106, 0))
				}
			end
		end
	end
end)

1 answer

local Raycast = workspace:Raycast(script.Parent.Position,script.Parent.CFrame.LookVector*25)

maybe try this instead

2 comments

0

or you could just use touched instead

0

touched events are worse they don't hit everytime plus they hit before hitting the ground

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