Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 6 years ago

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

Log in to vote
0
Answered by
Avigant 2374 Moderation Voter Community Moderator
6 years ago

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
0
Makes sense, should work. sweetkid01 176 — 6y
Ad
Log in to vote
0
Answered by
Zeluxis 100
6 years ago

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.

0
But how do I do it with events like TouchEnded? sweetkid01 176 — 6y
0
This isn't what he was asking, and you should use Instance:GetPropertyChangedSignal() to check for properties being changed when possible anyway. Avigant 2374 — 6y

Answer this question