Raycast Fails To Do What I'm Requesting

Hello,

I’m trying to make a bomb for my game called the disco bomb, and I wanted to add a visual effect that makes a dance floor spawn at the position under the bomb. I’m currently having two issues where

  1. The loop never breaks for some reason, and the bomb never gets deleted and the dance floor never becomes visible.
    image

  2. The dance floor kind of floats of the floor even though I want it to go directly under the bomb and lay on top of a part on the ground.

image

I’m not sure why this is happening, and there are no errors in the console that I can follow that can help me figure out a solution to these two issues.

Here is the script.

	local region3Visual = Instance.new("Part") -- The visualized part for the region3.
	region3Visual.Name = "blastRadiousVisual"
	region3Visual.CanCollide = false
	region3Visual.Size = region3.Size
	region3Visual.CFrame = region3.CFrame
	region3Visual.Anchored = true
	region3Visual.Transparency = .5
	region3Visual.Parent = workspace.Terrain
	region3Visual.BrickColor = BrickColor.new("Persimmon")
	local explosion = Instance.new("Explosion") -- The explosion instance
	explosion.Parent = bomb
	explosion.Position = bomb.Position
	explosion.BlastRadius = 0
	
	explosion.DestroyJointRadiusPercent = 0
	explosion.BlastPressure = 0

	explosion.BlastRadius = blastRegion3L

	local overlapParams = OverlapParams.new()
	overlapParams.FilterDescendantsInstances = {tool, tool.Handle, region3Visual}

	local parts = workspace:GetPartBoundsInBox(region3.CFrame, region3.Size, overlapParams)
	
	local discoBall = tool:WaitForChild("DiscoBall"):Clone() -- A disco ball which I've yet to add.
	discoBall.Parent = bomb
	
	local danceFloor = tool:WaitForChild("DanceFloor"):Clone() -- The Dance Floor
	danceFloor.Parent = bomb
	
	local origin = bomb.Position
	local direction = Vector3.new(0, -50, 0)
	local floorRaycast
	local raycastParams = RaycastParams.new() 
	raycastParams.FilterType = Enum.RaycastFilterType.Exclude
	raycastParams.IgnoreWater = true
	raycastParams.FilterDescendantsInstances = {tool, user, region3Visual}
	
	while task.wait() do
		floorRaycast = workspace:Raycast(origin, direction, raycastParams) -- The raycast that points downwards from the bomb to figure out where the dance floor should be placed.
		
		if floorRaycast then	
			if floorRaycast.Instance:IsA("Part") or floorRaycast.Instance:IsA("Union") then
				danceFloor:MoveTo(floorRaycast.Position) 
				
				for i, v in pairs(danceFloor:GetDescendants()) do -- Makes the dance floor visible after its position is set, doesn't appear for some reason in the first issue listed.
					if v:IsA("Part") then
						v.Transparency = 0
					end
				end
				
				break
			end
		end
	end
1 Like

Don’t use model:MoveTo in this case:

If there are any obstructions where the model is to be moved, such as Terrain or other BaseParts, the model will be moved vertically upward until there is nothing in the way. If this behavior is not desired, PVInstance:PivotTo() should be used instead.
- Model | Documentation - Roblox Creator Hub

You might still have to edit the model’s pivot which the wiki should also explain how to do.

That ended up working, but now I’m facing an issue where for soome reason the bottom part of the model just goes under the baseplate.
image

Just add an offset,

danceFloor:PivotTo(floorRaycast.Position + Vector3.new(0, floorRaycast.Instance.Size.Y /2, 0))
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.