Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why doesnt this work?

The script says it all i just want to click and it makes explosions where the mouse is

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

    mouse.Button1Down:connect(function()

    local e = Instance.new("Explosion")
        e.Parent = game.Workspace
        e.BlastPressure = 10 -- Edit this according to your needs.
        e.BlastRadius = 10 -- Edit this according to your needs, as well.
        e.Position =  mouse.hit -- This will place the explosion at your mouse.

end)


2 answers

✓ Accepted answer

There's probably a much better way to do this but what I've done here is created an invisible part at your mouse, and simply set the explosions position to the part.

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

    mouse.Button1Down:connect(function()

	local m = Instance.new("Part")
	m.Anchored = true
	m.CanCollide = false
	m.Transparency = 1
	m.Size = Vector3.new (1,1,1)
	m.Parent = game.Workspace
	m.CFrame = mouse.hit
	wait()
		
		local e = Instance.new("Explosion")
	        e.BlastPressure = 10 
	        e.BlastRadius = 10 
	        e.Position =  m.Position 
			e.Parent = game.Workspace
			m:Destroy()

end)

I Tested it in studio and it worked. Let me know if it helped!

2 comments

1

Gosh dangit ya beat me to it.

0

Thanks, I'm still learning lots of scripting to make a good game...

The reason it doesn't work is that you're setting the parent to workspace before you're setting the other properties. As soon as an explosion exists in workspace, it explodes. Set the parent last.

This discussion is preserved as it was. New answers, comments, and votes are closed.