Script doesn't work please help

  1. What do you want to achieve?
    I want make it so when u press Q it turns on and if u press again it turns off

  2. What is the issue? It says infinite yield possible on WaitForChild(“Stand”) on output, doesn’t work

  3. What solutions have you tried so far? I tried everything I even trying copying a code from yt

 local rp = game:GetService("ReplicatedStorage")
local summon = rp:WaitForChild("Summon")
local tweenservice = game:GetService("TweenService")

local debris = game:GetService("Debris")

summon.OnServerEvent:Connect(function(Player, IsActive)
	local char = Player.Character
	local humanoid = char.Humanoid
	local humrp = char.HumanoidRootPart
	
	if IsActive then
		local Stand = script:WaitForChild("Stand"):Clone()
		
		for _, part in pairs(Stand:GetChildren()) do
			if part:IsA("BasePart") then
				part.Transparency = 1
			end
		end
		Stand.Parent = char
		Stand.PrimaryPart.CFrame = humrp.CFrame
		
		local weld = Instance.new("ManualWeld")
		weld.Name = "Controller"
		weld.Part0 = Stand.PrimaryPart
		weld.Part1 = humrp
		weld.C0 = weld.Part0.CFrame:ToObjectSpace(weld.Part1.CFrame)
		weld.Parent = weld.Part0
		
		local animcontrol = Stand:FindFirstChild("AnimControl")
		local StandH = Stand.HumanoidRootPart
		
		local idle = animcontrol:LoadAnimation(script.Idle)
		idle:Play()
		
		for _, part in pairs(Stand:GetChildren()) do
			if part:IsA("BasePart")  and part ~= StandH then
				local goal = {}
				goal.Transparency = 0
				local info = TweenInfo.new(.5)
				local tween = tweenservice:Create(part,info,goal)
				tween:Play()
			end
		end
	else
		local Stan1d = char:FindFirstChild("Stand")
		if Stan1d then
			local Controller = Stan1d.PrimaryPart:FindFirstChild("Controller")
			if Controller then
				
				local standHumrp = Stan1d:FindFirstChild("HumanoidRootPart")
				
				for _, part in pairs(Stan1d:GetChildren()) do
					if part:IsA("BasePart")  and part ~= standHumrp then
						local goal = {}
						goal.Transparency = 0
						local info = TweenInfo.new(.5)
						local tween = tweenservice:Create(part,info,goal)
						tween:Play()
					end
				end
				
				
				local goal = {}
				goal.C0 =Controller.Part0.CFrame:ToObjectSpace(Controller.Part1.CFrame)
				goal.C1=Controller.Part0.CFrame:ToObjectSpace(Controller.Part1.CFrame  * CFrame.new(0,0,0))
				local info = TweenInfo.new(.5)
				local tween = tweenservice:Create(Controller,info,goal)
				tween:Play()
				
				tween.Completed:Connect(function()
					 debris:AddItem(Stan1d, .05)
				end)
			end
		end
		end
end)
1 Like

local Stand = script:WaitForChild("Stand"):Clone()
Show all children of the script in Explorer

2 Likes

1e1382fca1fb57e2571636a52086da90

1 Like

When it this object appear in the script? Is it in the Explorer or an another script generates this object here after your game runs?
An alternative question: Is Stand model here in edit mode?
A potential solution if yes:
You don’t have to worry about server replication speed, making WaitForChild() often useless for server scripts. The infinite yield is weird (I can see that the script is waiting for Stand and Stand model is here). Try delcaring Stand clone like this:
image

2 Likes