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!