wait(2)
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild(“Humanoid”) then
hit.Parent.HumanoidRootPart.CFrame = CFrame.new(46, 60.25, -110.919)
end
end)
wait(2)
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild(“Humanoid”) then
hit.Parent.HumanoidRootPart.CFrame = CFrame.new(46, 60.25, -110.919)
end
end)
Could you elaborate on what you’re trying to make?
the wait function doesn’t work.
example it should wait 2 seconds before it teleports a player.
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild(“Humanoid”) then wait(2)
hit.Parent.HumanoidRootPart.CFrame = CFrame.new(46, 60.25, -110.919)
end
end)
This script will wait 2 seconds before teleporting player that touched the part:
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChildWhichIsA(“Humanoid”) then
task.wait(2)
hit.Parent.HumanoidRootPart.CFrame = CFrame.new(46, 60.25, -110.919)
end
end)
This is still fatly I do not know why.
Well right now you have it waiting, then waiting again for a player to touch before it “teleports them”.
I suggest doing something like this:
task.delay(2, function()
script.Parent.Touched:Connect(function(hitPart)
if (hitPart.Parent:FindFirstChildWhichIsA('Humanoid')) then
hitPart.Parent:MoveTo(Vector2.new(46, 60.25, -110.919))
end
end)
end)
If the player is touching the part before the code activates it won’t work, as they didn’t touch it, they are touching it already, they will have to get off the part and step back on it for this to work properly.
Bro, I make such stupid mistakes. I have a question how do you know what to put in the code?
I just have a lot of experience with studio, if you are learning youtube helps alot as well as:
Wait do you know why, in 6 years Roblox has never asked me to commit something and now it is asking me? If I don’t it won’t let me publish the scripts. I think it said commit. Today is the first time it ever showed this.
Open studio, go to the home tab, open game settings, go to “other” and turn off collaborative editing.
it is not working for me. I do not know why.
Humanoid doesn’t get picked up and then.
Sorry that was my bad. I accidentally used incorrect quotations in my post try this instead:
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChildWhichIsA("Humanoid") then
task.wait(2)
hit.Parent.HumanoidRootPart.CFrame = CFrame.new(46, 60.25, -110.919)
end
end)
This doesn’t check if the player exists the part. I’m confused on that psrt
I am confused. Can you please elaborate more on what you are trying to achieve?
Edit: The coding example I have displayed above checks if the player that touched the part has a Humanoid which is what every player has and if it doesn’t, further code will not execute.
I think you haven’t understood what your script does here:
The wait()
method is also superseded by task.wait()
, and the former nowadays is somewhat inaccurate.
Have you tried using a debounce?