Infinite yield possible on 'Workspace:WaitForChild("Character")'

local EggOpener = script.Parent
wait(1)
local char = game.Workspace:WaitForChild("Character")
local humRoot = char.HumanoidRootPart


local Magnitude = (humRoot.Position- EggOpener.Position).magnitude
print(Magnitude)

17:10:49.959 Infinite yield possible on ‘Workspace:WaitForChild(“Character”)’ - Studio
local script in starterplayerscripts

repeat wait() game.Workspace:FindFirstChild(Character) until game.Workspace:FindFirstChild(Character) ~= nil

local script? Can you explain what you’re* trying to do?

The EggOpenerPart is a part in the Egg and I want to get the magnitude of the egg and HumanoidRootPart

I meant like is your script a local script or not? a lil more depth in your explanation could help aswell

Like why didn’t you connect an event? if possible

local char = game.Workspace:WaitForChild("Character") or game.Workspace:FindFirstChild("Character")

I have a part near the egg and I want to see the magnitude of the eggPart and the HumanoidRootPart

use game.Workspace:FindFirstChild(Character.Name) not game.Workspace:FindFirstChild("Character")

if you use game.Workspace:FindFirstChild(“Character”) this mean your looking for name called Character

I know you said that but is your script a local script or not. I just need to know so i can properly help and give recommendations

Its a local script sorry If i was not clear enough

look
using this code mean("character")your looking for something called character
using this code mean (character.Name)your looking for opject have same name with player character

Where is the script located? within StaterGui or something? I’m very curious i have an idea of what you can use

The Script is in StarterPlayerScripts

Here is a better way to test the magnitude you wanted

local Players=  game:GetService("Players")
local Player = Player.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")

local EggOpener = script.Parent --// Im unsure about this...

While true do
wait(1)
local Magnitude = (HumanoidRootPart .Position- EggOpener.Position).magnitude
print(Magnitude)
end

Resources
https://developer.roblox.com/en-us/api-reference/property/Players/LocalPlayer
https://developer.roblox.com/en-us/api-reference/event/Player/CharacterAdded

2 Likes
local player = game.Players.LocalPlayer

repeat wait() player:FindFirstChild(Character) until player:FindFirstChild(Character) ~= nil

local Character = player:FindFirstChild(Character)

what is the EggOpener exactly? and where is it located

Yes It worked Thank you so much! God(or any other Gods you believe in) Bless you.

1 Like