In the workspace, I have a ‘Maps’ folder, and inside it are the maps. I currently have a folder called ‘DefaultMap’ in it, and inside that folder, I have the part that I want the fireball to hit. The script that I’m currently using to make the fireball detect for the map parts literally does the opposite. Instead of hitting parts that are in the maps, they hit parts that are outside of the maps and phase through parts that are in the map.
for a, b in pairs(workspace.Maps:GetChildren()) do
for c, d in pairs(b:GetChildren()) do
if hit == d then
Here’s the whole hit detection script:
newFireball.Touched:Connect(function(hit)
if hit.Parent.Name ~= player.Name and hit.Parent:FindFirstChild("Humanoid") then
hit.Parent.Humanoid:TakeDamage(dmg)
newFireball:Destroy()
local newExplosion = Explosion:Clone()
newExplosion.CFrame = newFireball.CFrame * CFrame.new(Vector3.new(0,0,-5))
newExplosion.Parent = game.Workspace
newExplosion.Sound:Play()
local ExplosionAnim = TweenInfo.new(
0.4,
Enum.EasingStyle.Linear,
Enum.EasingDirection.Out,
0,
false,
0
)
local size = {Size = Vector3.new(25, 25, 25)}
local tween = TweenService:Create(newExplosion, ExplosionAnim, {Transparency = 1})
local tween2 = TweenService:Create(newExplosion, ExplosionAnim, size)
tween:Play()
tween2:Play()
local stuntag = Instance.new("ObjectValue")
stuntag.Name = "StunEffect"
stuntag.Parent = hit.Parent.Humanoid
game.Debris:AddItem(stuntag,StunDuration)
local burntag = Instance.new("ObjectValue")
burntag.Name = "BurnEffect"
burntag.Parent = hit.Parent.Humanoid
game.Debris:AddItem(burntag,burnlength)
local Tagged = Instance.new("ObjectValue")
Tagged.Name = "killer"
Tagged.Value = player
Tagged.Parent = hit.Parent.Humanoid
game.Debris:AddItem(Tagged,1)
game.Debris:AddItem(newExplosion, 1)
for a, b in pairs(workspace.Maps:GetChildren()) do
for c, d in pairs(b:GetChildren()) do
if hit == d then
newFireball:Destroy()
newExplosion.CFrame = newFireball.CFrame * CFrame.new(Vector3.new(0,0,-5))
newExplosion.Parent = game.Workspace
newExplosion.Sound:Play()
tween:Play()
tween2:Play()
game.Debris:AddItem(newExplosion, 1)
end
end
end
Like @FurukanDev stated we need more code, but I already am noticing that you shouldn’t use :GetChildren(), you should instead use :GetDescendants() (However this won’t fix your problem, please give more code)
I managed to fix the problem, it turns out that the fireball was only detecting for humanoids. I decided to put the map parts detection in front of the humanoid detection and it pretty much worked.
newFireball.Touched:Connect(function(hit)
for a, b in ipairs(workspace.Maps:GetChildren()) do
for c, d in ipairs(b:GetChildren()) do
if hit == d then
newFireball:Destroy()
local newExplosion = Explosion:Clone()
newExplosion.CFrame = newFireball.CFrame * CFrame.new(Vector3.new(0,0,-5))
newExplosion.Parent = game.Workspace
newExplosion.Sound:Play()
local ExplosionAnim = TweenInfo.new(
0.4,
Enum.EasingStyle.Linear,
Enum.EasingDirection.Out,
0,
false,
0
)
local size = {Size = Vector3.new(25, 25, 25)}
local tween = TweenService:Create(newExplosion, ExplosionAnim, {Transparency = 1})
local tween2 = TweenService:Create(newExplosion, ExplosionAnim, size)
tween:Play()
tween2:Play()
game.Debris:AddItem(newExplosion, 1)
end
end
end
if hit.Parent.Name ~= player.Name and hit.Parent:FindFirstChild("Humanoid") then
hit.Parent.Humanoid:TakeDamage(dmg)
newFireball:Destroy()
local newExplosion = Explosion:Clone()
newExplosion.CFrame = newFireball.CFrame * CFrame.new(Vector3.new(0,0,-5))
newExplosion.Parent = game.Workspace
newExplosion.Sound:Play()
local ExplosionAnim = TweenInfo.new(
0.4,
Enum.EasingStyle.Linear,
Enum.EasingDirection.Out,
0,
false,
0
)
local size = {Size = Vector3.new(25, 25, 25)}
local tween = TweenService:Create(newExplosion, ExplosionAnim, {Transparency = 1})
local tween2 = TweenService:Create(newExplosion, ExplosionAnim, size)
tween:Play()
tween2:Play()
game.Debris:AddItem(newExplosion, 1)
local stuntag = Instance.new("ObjectValue")
stuntag.Name = "StunEffect"
stuntag.Parent = hit.Parent.Humanoid
game.Debris:AddItem(stuntag,StunDuration)
local burntag = Instance.new("ObjectValue")
burntag.Name = "BurnEffect"
burntag.Parent = hit.Parent.Humanoid
game.Debris:AddItem(burntag,burnlength)
local Tagged = Instance.new("ObjectValue")
Tagged.Name = "killer"
Tagged.Value = player
Tagged.Parent = hit.Parent.Humanoid
game.Debris:AddItem(Tagged,1)
end
end)
end)