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

Spawning A Block And An Explosion With It Failed?

function onTouch(hit) while true do local Wow = Instance.new("Part") Wow.Parent = game.Workspace Wow.Position = Vector3.new(-1609, 3473.895, -2417) Wow.CanCollide = false Wow.Locked = true Wow.BrickColor = BrickColor.new("New Yeller") Wow.Shape = ("Ball") wait(1) local Ex = Instance.new("Explosion") Ex.Parent = game.Workspace Ex.Position = Wow.Position Ex.BlastPressure = 5000000 Ex.BlastRadius = 10 Wow.Destroy() local M = Instance.new("Hint") M.Text = "SOMEONE HAS TOUCHED EPIC FACE'S BLOCK" wait(5) M.Destroy()

end

end

script.parent.Touched:connect(onTouch)

As you can see I am making a small easter egg in my "game" for me and my friends and my code failed. No errors, it just won't work. I thought it might be the explosion causing the problem, but then it would spawn the part but not the explosion. It's probably something completely obvious and I'm too blind to see it. :P Thanks!

1 answer

✓ Accepted answer

If I read the discombobulated code correctly, this is the most likely setup of it.

function onTouch(hit)
	while true do
		local Wow = Instance.new("Part")
		Wow.Parent = game.Workspace
		Wow.Position = Vector3.new(-1609, 3473.895, -2417)
		Wow.CanCollide = false
		Wow.Locked = true
		Wow.BrickColor = BrickColor.new("New Yeller")
		Wow.Shape = ("Ball")
		wait(1)
		local Ex = Instance.new("Explosion")
		Ex.Parent = game.Workspace
		Ex.Position = Wow.Position
		Ex.BlastPressure = 5000000
		Ex.BlastRadius = 10
		Wow.Destroy()
		local M = Instance.new("Hint")
		M.Text = "SOMEONE HAS TOUCHED EPIC FACE'S BLOCK"
		wait(5)
		M.Destroy()
	end
end

script.parent.Touched:connect(onTouch)

Anyways from my limited experience with the only function I know by heart and soul (Touched) it appears that you're going for a direct "while true do"loop for whatever reason.

The function seems to be set out normal in regards to spawning in parts and such

	local Wow = Instance.new("Part")
		Wow.Parent = game.Workspace
		Wow.Position = Vector3.new(-1609, 3473.895, -2417)
		Wow.CanCollide = false
		Wow.Locked = true
		Wow.BrickColor = BrickColor.new("New Yeller")
		Wow.Shape = ("Ball")

Creating a Ball shaped part at Position (-1609, 3473.895, -2417) that is yellow, and non collidable and

	wait(1)
		local Ex = Instance.new("Explosion")
		Ex.Parent = game.Workspace
		Ex.Position = Wow.Position
		Ex.BlastPressure = 5000000
		Ex.BlastRadius = 10
		Wow.Destroy()
		local M = Instance.new("Hint")
		M.Text = "SOMEONE HAS TOUCHED EPIC FACE'S BLOCK"

A very powerful explosion set at the position of the newly formed "Wow" part that gives text and destroys the wow Part.

It does , however, seem that you've forgotten to call a part of the script that actually detects the player's presence.

Adding that in after the function which I'll localize I get

local function onTouch(hit)
	local explode = hit.Parent
	local humanoid = explode:FindFirstChild('Humanoid')
	if humanoid then
		local Wow = Instance.new("Part")
		Wow.Parent = game.Workspace
		Wow.Position = Vector3.new(-1609, 3473.895, -2417)
		Wow.CanCollide = false
		Wow.Locked = true
		Wow.BrickColor = BrickColor.new("New Yeller")
		Wow.Shape = ("Ball")
		wait(1)
		local Ex = Instance.new("Explosion")
		Ex.Parent = game.Workspace
		Ex.Position = Wow.Position
		Ex.BlastPressure = 5000000
		Ex.BlastRadius = 10
		Wow.Destroy()
		local M = Instance.new("Hint")
		M.Text = "SOMEONE HAS TOUCHED EPIC FACE'S BLOCK"
		wait(5)
		M.Destroy()
	end
end

script.Parent.Touched:connect(onTouch)

with the Humanoid detection occurring on lines 2-4

Now on the last line I get an error with parenting and the very fun likes, so for the sake of me personally being able to get past it, I'll bundle the whole thing into a neat little package in a variable called surpise

local surprise = script.Parent

local function onTouch(hit)
	local explode = hit.Parent
	local humanoid = explode:FindFirstChild('Humanoid')
	if humanoid then
		local Wow = Instance.new("Part")
		Wow.Parent = game.Workspace
		Wow.Position = Vector3.new(33, 0.5, -7) --This is the location of the part in my own testing world for the sake of my debugging. Just change it back to your original Vect3 when ready
		Wow.CanCollide = false
		Wow.Locked = true
		Wow.BrickColor = BrickColor.new("New Yeller")
		Wow.Shape = ("Ball")
		wait(1)
		local Ex = Instance.new("Explosion")
		Ex.Parent = game.Workspace
		Ex.Position = Wow.Position
		Ex.BlastPressure = 5000000
		Ex.BlastRadius = 10
		Wow:Destroy()
		local M = Instance.new("Hint")
		M.Text = "SOMEONE HAS TOUCHED EPIC FACE'S BLOCK"
		wait(5)
		M:Destroy()
	end
end

surprise.Touched:connect(onTouch)

Now when I touch it I get the yellow ball plopped on top of me that decimates me after a time. The only thing I didn't get was a "Hint" which I have no experience with, but it seems minor with your issue. The yellow ball, however keeps getting copied and copied and copied. So lets add a simple little debounce to the script.

local surprise = script.Parent
local canBoom = true
local cooldown = 7

local function onTouch(hit)
	local explode = hit.Parent
	local humanoid = explode:FindFirstChild('Humanoid')
	if humanoid and canBoom then
		canBoom = false
		local Wow = Instance.new("Part")
		Wow.Parent = game.Workspace
		Wow.Position = Vector3.new(33, 0.5, -7)
		Wow.CanCollide = false
		Wow.Locked = true
		Wow.BrickColor = BrickColor.new("New Yeller")
		Wow.Shape = ("Ball")
		wait(1)
		local Ex = Instance.new("Explosion")
		Ex.Parent = game.Workspace
		Ex.Position = Wow.Position
		Ex.BlastPressure = 5000000
		Ex.BlastRadius = 10
		Wow:Destroy()
		local M = Instance.new("Hint")
		M.Text = "SOMEONE HAS TOUCHED EPIC FACE'S BLOCK"
		wait(5)
		M:Destroy()
		wait(cooldown)
		canBoom = true
	end
end

surprise.Touched:connect(onTouch)

the function canBoom is required to be true for the inner script to fire, after the touch is detected it goes false to keep it from firing again, then at the end after a cooldown of whatever time you want (May probably not needed due to your wait right before, but meh whatever) it activates once more allowing the boom to happen. So now putting everything back to what I presume to apply to your world you get the final beautiful baby

local surprise = script.Parent
local canBoom = true
local cooldown = 7

local function onTouch(hit)
	local explode = hit.Parent
	local humanoid = explode:FindFirstChild('Humanoid')
	if humanoid and canBoom then
		canBoom = false
		local Wow = Instance.new("Part")
		Wow.Parent = game.Workspace
		Wow.Position = Vector3.new(-1609, 3473.895, -2417) --Put back to your coordinates
		Wow.CanCollide = false
		Wow.Locked = true
		Wow.BrickColor = BrickColor.new("New Yeller")
		Wow.Shape = ("Ball")
		wait(1)
		local Ex = Instance.new("Explosion")
		Ex.Parent = game.Workspace
		Ex.Position = Wow.Position
		Ex.BlastPressure = 5000000
		Ex.BlastRadius = 10
		Wow:Destroy()
		local M = Instance.new("Hint")
		M.Text = "SOMEONE HAS TOUCHED EPIC FACE'S BLOCK"
		wait(5)
		M:Destroy()
		wait(cooldown)
		canBoom = true
	end
end

surprise.Touched:connect(onTouch)

I hope this helps you a ton! As this was my first answer given, because I only have teachable experience with the touched function and all it's fun. Good luck with your game!

~MBacon15

1 comment

0

Also thanks for having the code all jumbled up like that, gives me extra things to keep me occupied, and allows me to test my beginners script reading skills. The only thing I was unable to get anything with was the Instance.new("Hint")

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