Two functions not working

My goal here is to create a script that loops different shapes for a part, and a button that activates only when touched by a humanoid, and when that particular part’s shape is a ball. The button will turn the player’s health to 25

local losButton = script.Parent
local theDamaged = game.Workspace.BlockDamage

-- will change the part's shapes (loop)
local function shapeSwitch ()
	while true do
		theDamaged.Shape = ("Cylinder")
		wait(3)
		theDamaged.Shape = ("Ball")
		wait(3)
		theDamaged.Shape =("Block")
		wait(3)
	end
end

--will detect what touched the part
local function whenTouch(partthattouched)
	local gamer = partthattouched.Parent
	
	--search for humanoid
	local theAffected = gamer:FindFirstChildWhichIsA("Humanoid")
	
	--if a humanoid is detected and theDamaged's shape is a Ball, humanoids health will change to 25
	if theAffected and theDamaged.Shape == ("Ball") then
		theAffected.Health = 25
	end

end

shapeSwitch()

losButton.Touched:Connect(whenTouch)

I’ve done some attempts on fixing it, like trying to switch the functions, still doesn’t work. However, it appears that only one function can fire in the script.

-When the shapeSwitch function fires, the whenTouch function won’t work
-the whenTouch function only fires when i don’t activate/when i erase the shapeSwitch function (and also removing theDamaged shape ball variable)

So it kind of seems like the two functions can’t coexist together…so my best guess is that i need help on making these two functions work together. I just need any help, really.

I’d also be happy to receive some advice regarding my code!

use

spawn(shapeSwitch)

or

coroutine.wrap(shapeSwitch)()

The coroutine.wrap one wont work, you forgot to call the wrapped function

coroutine.wrap(shapeSwitch)()

That’s not necessary. Just move the Touched connection above the shapeSwitch call.

1 Like

Not sure to where to put these commands or what they do, so i changed the shapeSwitch() function call to these ones.

Health still doesnt change

I moved the Touched connection above and it still doesn’t work