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
-
The loop never breaks for some reason, and the bomb never gets deleted and the dance floor never becomes visible.
-
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.
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