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

Can I mix a while loop with a function, and then call the function?

So, I'm making a script, for a coin. The coin is supposed to spin all the time, until someone touches it. When you touch it, it plays a sound, and then the coin is destroyed. Here's my script:

local part = script.Parent
local db = false

while wait() do
	part.CFrame = part.CFrame * CFrame.Angles(0,0,0.1)
end


function coin(hit)
	local human = hit.Parent:FindFirstChild("Humanoid")
	if not db then
		if human then
			db = true
			
			game.Workspace.coin.Sound:Play()
			script.Parent.Parent:Destroy()
			
			db = false
			
		end
	end
end


part.Touched:connect(coin)

The coin spins the way it should, but it doesn't destroy or play the sound. All help is appreciated! Also, output doesn't give any errors.

2 comments

0

no.

0

^ Was that necessary?

1 answer

✓ Accepted answer

Put your while loop either in a spawn(function() WHILE LOOP end) or put it underneath all your defined functions and connection lines

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