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

[UNANSWERED] Not doing the wait function?

Ok so with this script, what ever touches it, will turn into the "Mesh" but after "wait(2)" what ever else touches it then would turn into "Mesh2" and it will be repeated. But it only turns everything into "Mesh"?

B = script.Mesh
A = script.Mesh2

function onTouched(part) 
BC = B:clone() 
BC.Parent = part 
script.Parent.CanCollide = false
wait(2)
function onTouched(part) 
AC = A:clone() 
AC.Parent = part 
script.Parent.CanCollide = false 
   end
end 

script.Parent.Touched:connect(onTouched) 

2 comments

0

So do you want the things that touch it to turn to the second mesh only after it has been touched once already? Or more like a cycle where it is either mesh1 or mesh 2 and changes every 2 seconds?

0

It would be like a cycle, for example: all parts coming down the conveyor belt, say the first one touches it, it will turn into "Mesh" and say the next part coming down doesnt touch it until after 2 seconds, so that part would be "Mesh 2" and it will be a repition.

2 answers

✓ Accepted answer
B = script.Mesh
A = script.Mesh2

while true do
local part = script.Parent.Touched:wait()
-- Wait for first touch
BC = B:clone() 
BC.Parent = part 
script.Parent.CanCollide = false
wait(2)
part = script.Parent.Touched:wait();
-- Wait for second touch
AC = A:clone() 
AC.Parent = part 
script.Parent.CanCollide = false 
end

:wait() waits for the Event to fire and returns the arguments that would go in the connected functions.

1 comment

0

only turns them into "Mesh2"?

Try this

B = script.Mesh
A = script.Mesh2

local x = true

function onTouched(part)
	if x then
		BC = B:clone() 
		BC.Parent = part 
		script.Parent.CanCollide = false
		wait(2)
		x = false
	elseif not x then
		AC = A:clone() 
		AC.Parent = part 
		script.Parent.CanCollide = false
	end
end 

script.Parent.Touched:connect(onTouched) 

1 comment

0

now it only turns all the parts that touch it into "Mesh2"

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