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

Can you make :Wait() only connect if a certain parameter of the event has a certain value?

Y'know the RobloxScriptService thing :Wait()?

like

-- :GetService() is for the laughs
game:GetService("Workspace").Part.Touched:Wait()
-- blab

I was wondering if you could like, make it so that the event would only get through :Wait() if a parameter of it had a certain value.

I mean like sorta like

script.Parent.Touched:Connect(function(otherThing)
	local player = game:GetService("Players"):GetPlayerFromCharacter(otherThing.Parent)
	if player then
		game:GetService("ReplicatedStorage").TouchEvent:FireClient(player)
		-- importent
			script.Parent.TouchEnded:Wait(otherPart = otherThing)
		-- end
		game:GetService("ReplicatedStorage").MoveEvent:FireClient(player)
	end
end)

Soo.... yes or no?

2 answers

✓ Accepted answer

RBXScriptSignal:Wait() takes no arguments, but it returns the values the event was fired with, so we could do this:

local touchedPart = part.Touched:Wait()

if touchedPart.Name ~= "The Part We Want" then
	return
end

-- Code

1 comment

0

Makes sense, should work.

Yes, you can.

If you use repeat wait(), you can repeat the wait command until a certain parameter has been met. For example:

repeat wait() until game.Workspace.Part.CanCollide==false

This would wait until the Part does not Collide before proceeding onto the next part of your code.

2 comments

0

But how do I do it with events like TouchEnded?

0

This isn't what he was asking, and you should use Instance:GetPropertyChangedSignal() to check for properties being changed when possible anyway.

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