1.
script.Parent.Touched:connect(function() script.Parent:FindFirstChild("Humanoid") -- Checks for player local Scrip = script.Parent Instance.new("Explosion", game.Workspace.Part) -- Puts Explosion into a part local Explosion = game.Workspace.Part.Explosion game.Workspace.Part.Explosion.Position = Scrip.Position -- Gives explosion a Position end)
Vs.
2.
script.Parent.Touched:connect(function() script.Parent:FindFirstChild("Humanoid") -- Checks for player local Explosion = Instance.new("Explosion",script.Parent) -- Explosion instance and location Explosion.Position = script.Parent.Position -- Gives Explosion a position end)
Why does script 2 works better than Script 1? Script 1 explodes in two different places at the same time, the workspace at (0, 0, 0) and in the brick.
Script 2 Explodes in the brick only.
What's the difference? I've been reading this for a while, and both of them gives the explosion a Location, a Position, and even a Parent. What's wrong here?
I'm not sure exactly what it could be, but Lua instructions take a millisecond or two to process, so the extra variable creation in the first is probably causing the issues.
Try this to see if it's any better:
script.Parent.Touched:connect(function() script.Parent:FindFirstChild("Humanoid") -- Checks for player local Explosion = Instance.new("Explosion", game.Workspace.Part) --Instance.new returns the created Instance Explosion.Position = script.Parent.Position --And you should probably reference the variable you just created. Also, creating a variable for something you use exactly once probably isn't a good idea. end)