Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why doesnt this work?

Asked by 8 years ago

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

Log in to vote
3
Answered by
Chronomad 180
8 years ago

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!

1
Gosh dangit ya beat me to it. disassembling 48 — 8y
0
Thanks, I'm still learning lots of scripting to make a good game... UltraUnitMode 419 — 8y
Ad
Log in to vote
1
Answered by
1waffle1 2908 Trusted Badge of Merit Moderation Voter Community Moderator
8 years ago

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.

Answer this question