A few things wrong with your script.
Don't use mouse:KeyDown, use UserInputService.InputBegan instead. UIS is more reliable and up to date. https://developer.roblox.com/api-reference/event/UserInputService/InputBegan
The second argument of Instance.new() is deprecated, which means you shouldn't use it.
You have to make the explosion a variable. (local explosion = Instance.new("Explosion")
Now that we got the problems out the way, let's go over and see how to fix the script:
You need a character defined (in a variable). A player is the client, where a character is the person you walk around as. You also need to add the explosion variable, so you can manage it easier. So, your script should start like this:
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local explosion = Instance.new("Explosion")
That's better.
Now, you started off the explosion right. Explosions, well, explode as soon as they're parented into workspace, or a descendant of workspace. So, all you have to do is fix this simple script, using the help I gave you. Keep in mind that you should :Clone() the explosion and make a 2nd variable for it, then parent it to the character's humanoidrootpart, so the first explosion doesn't dissapear from the game's memory.
Keep in mind this is local sided, so it will explode only you, other players won't see the explosion or be damaged by it. To make it work with other people, learn about remotes and experiment around instead.
Full script for future refference below:
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local explosion = Instance.new("Explosion")
local UIS = game:GetService("UserInputService")
UIS.InputBegan:Connect(function(input,gp)
if not gp and input.KeyCode == Enum.KeyCode.Q then
local ex2 = explosion:Clone()
ex2.Parent = char.HumanoidRootPart
end
end)
If you found this useful, mark this as the answer!
4 comments
further define the explosion
How, exactly?
This script is very outdated
Do you think you could clarify how to write it?