I made a script that detects if “Explosion” is added to the workspace or not, but when I use print(Child.Position) it gives me Vector3.new(0,0,0). Which is an absolutely wrong Position. How can I fix this?
NOTE: I put a moddified Explosion It’s position shouldn’t be Vector3.new(0,0,0)
game.Workspace.ChildAdded:Connect(function()
local Child = game.Workspace:FindFirstChild("Explosion")
print(Child.Position)
if Child then
if Child == "Explosion" then
if (Child.Position - script.Parent.Glass.Position).Magnitude <= Child.BlastRadius then
for i = 1,8 do
local Wedge = script.Parent:FindFirstChild("Wedge"..i)
Wedge.Transparency = 0.75
end
script.Parent.Glass:Destroy()
end
end
end
end)
and
game.Workspace.ChildAdded:Connect(function(Child)
print(Child.Position)
if Child then
if Child == "Explosion" then
if (Child.Position - script.Parent.Glass.Position).Magnitude <= Child.BlastRadius then
for i = 1,8 do
local Wedge = script.Parent:FindFirstChild("Wedge"..i)
Wedge.Transparency = 0.75
end
script.Parent.Glass:Destroy()
end
end
end
end)
Did you set the explosion’s Position before or after you assigned its parent to workspace? If I’m not wrong, the script you provided would just detect it as soon as it is added to workspace, taking in the information that instant before it can recognize the position it was given.
Besides that (if you did assign the parent before the position property), it is bad practice to do so. It’s more expensive to set the properties of an object after you set the parent of it, as the client has to render it in after it’s been added to the workspace.
Here is your problem,
" The effect of an explosion is instantaneous. This means that although the position of an explosion can be changed after it has been set it cannot affect two different areas. Once an explosion has been ‘detonated’, shortly after parenting it to a descendant of the Workspace , it will not do so again. In some cases the visual effect of the explosion will move but it will have no effect.
For this reason a new Explosion should be created if the developer wants an explosion to appear at a different position. "
Meaning if you would want an Explosion at any position other then 0,0,0 you should manually change it’s position, also a better way to detect a player trying to destroy glass, which I assume you’re doing, is to see whether a player’s mouse is over it, and then clone an explosion through the same script.
Though i’m not sure whether that’s what you want.