Hi, I need to find a way to script a way for the queue to check if someone is standing on a brick, and then stop until the player has stopped standing on it. My issue is that I am unsure of how to script that, I have tried coding in while true do and lots of other issues, it sets a bool value to true when the player is standing on it. Here is a part of my current script:
local touch = script.Parent.NextPart.Value.IsTouching.Value == true
local waiting = script.Parent.NextPart.Value.IsTouching.Value == false
script.Parent.IsTouching.Value = true
while true do
wait(1)
if touch then
print("Waiting!")
wait(1)
elseif waiting then
if character and Players:GetPlayerFromCharacter(character) then
character.Humanoid:MoveTo(nextpart)
wait(1)
script.Parent.IsTouching.Value = false
NextPart.Touched:Connect(function(Touch)
if Touch.Parent:FindFirstChild("Humanoid") then -- Make sure a real player has touched it.
print("Waiting")
end
end)
There exists the TouchEnded event for parts which can be waited for. @ThoseNamesAreGood code can be extended to the following:
NextPart.Touched:Connect(function(character)
-- Make sure a real player has touched it.
if not character.Parent:FindFirstChild("Humanoid") then return end
-- Wait for the character to stop touching the part
print("Waiting")
while NextPart.TouchEnded:Wait() ~= character and character.Parent do end
-- Make sure the character is still valid, Parent is nil when destroyed
print("Stopped Waiting")
if not character.Parent then return end
-- Do your extra stuff here
character.Humanoid:MoveTo(nextpart)
end)
The TouchEnded event will trigger when any part stops touching it, therefore we can use a while loop and a condition to wait for the specific character to stop touching the part.
If a player leaves the game their character is destroyed so it is a good idea to test for this case, this is included in my example within the while loop and after.
That didn’t work, the full script I’m using is;
function onTouched(hit)
print("Part A!")
local nextpart = script.Parent.NextPart.Value
nextpart.Touched:Connect(function(character)
-- Make sure a real player has touched it.
if not character.Parent:FindFirstChild("Humanoid") then return end
-- Wait for the character to stop touching the part
print("Waiting")
while nextpart.TouchEnded:Wait() ~= character and character.Parent do end
-- Make sure the character is still valid, Parent is nil when destroyed
print("Stopped Waiting")
if not character.Parent then return end
-- Do your extra stuff here
character.Humanoid:MoveTo(nextpart)
end)
end
script.Parent.Touched:connect(onTouched)
Which part did not work, you need to give more details.
One naming error I made was calling the hit part “character” when it was a child of character. Therefore, the last line should be character.Parent because of this.
However, I copied this from your existing script as I’m not sure what you want it to do when it had stopped waiting.