Object does not exist even though it does

So, there’s this issue with my script. When the script is triggered, the thing works and it is able to identify the object inside the script. But the second time, it doesn’t. It says "Infinite yield possible on ‘Workspace.my username.KnifeThrow:WaitForChild(“Knife”)’. Here’s the script:

local rp = game:GetService(“ReplicatedStorage”)
local KnifeThrow = rp:WaitForChild(“TheWorldRemotes”):WaitForChild(“KnifeThrow”)

local Stand = workspace:FindFirstChild(Player.Name…" Stand"):WaitForChild(“Dummy”)
local animControl = Stand:WaitForChild(“AnimControl”)
if Stand then
local throw = animControl:LoadAnimation(script:WaitForChild(“Throw”))
local knife = script:WaitForChild(“Knife”)
knife.Parent = Stand:WaitForChild(“Right Arm”)
knife.Orientation = Vector3.new(0, -90, -90)
local RightArm = Stand:WaitForChild(“Right Arm”)
local weld = Instance.new(“Weld”)
if knife then
knife.Anchored= false
knife.Position = RightArm.Position
local hand = Stand:WaitForChild(“Right Arm”):WaitForChild(“hand”)
weld.Name = “Knife Weld”
weld.Part0 = knife
weld.Part1 = hand
weld.C0 = hand.CFrame:inverse() * knife.CFrame
weld.Parent = weld.Part0



Sorry if I didn’t explain well enough.

I don’t know for sure if this is causing it but you should separate 'TheWorldRemotes and KnifeThrow into two different variables, like so:

local theWorldRemotes = rp:WaitForChild(“TheWorldRemotes”)
local knifeThrow = theWorldRemotes:WaitForChild(“KnifeThrow”)

It’s not causing it; in my other scripts it’s able to detect remotes in it perfectly

When you clone the knife you need to make a reference to it. You do knife:Clone() but you never use the clone at all because there’s no reference to it.

When you perform actions on knife after you clone it, you’re not actually doing anything to the clone and you’re doing it on the actual knife. When you want the script to run again, the actual knife is not there because you parented it to Right Arm so the WaitForChild will wait indefinitely.

1 Like