Check if player has stand then define

Hello every, So I’m making a jjba game (yeah overdone i know) but i need some help
So In the script

local stands = chr:WaitForChild("StandS")
local rots = stands:WaitForChild("StandHumanoidRootPart")
local heds = stands:WaitForChild("Stand Head")
local faces = heds:WaitForChild("face")
local torss = stands:WaitForChild("Stand Torso")
local rarms = stands:WaitForChild("Stand Right Arm")
local larms = stands:WaitForChild("Stand Left Arm")
local rlegs = stands:WaitForChild("Stand Right Leg")
local llegs = stands:WaitForChild("Stand Left Leg")
local donutanim = human:LoadAnimation(rots.Donut)

Basically, I only need it to do this part if the players Isuser value is true


if isuser.Value == true then

local stands = chr:WaitForChild("StandS")

local rots = stands:WaitForChild("StandHumanoidRootPart")

local heds = stands:WaitForChild("Stand Head")

local faces = heds:WaitForChild("face")

local torss = stands:WaitForChild("Stand Torso")

local rarms = stands:WaitForChild("Stand Right Arm")

local larms = stands:WaitForChild("Stand Left Arm")

local rlegs = stands:WaitForChild("Stand Right Leg")

local llegs = stands:WaitForChild("Stand Left Leg")

local donutanim = human:LoadAnimation(rots.Donut)

end

But if i do this, they aren’t recognized by the rest of the script
image
How can i fix this? I’d rather keep this all in the same script

Because of scoping. Try to declare everything outside of the if statement before, then setting the values inside it.

Could I have a simple example of this?

I have issues focusing on stuff without usually seeing examples

local x
if a then
     x = 5
end
print(x)

This example would print 5.

if a then
     local x = 5
end
print(x)

This wouldn’t because of scoping.

Let me explain my script a little better though

So the Local variables (the things that they are referencing, like the StandS
only appear if the IsUser value = true

So idk if that would work

I see, I’ll try that out. Thank you

image

Theres still a few squiggles. Do you know why?

Get rid of the local part when you’re setting the value after declaring.

local x
x = 5

instead of

local x
local x = 5

Works great! thanks man. Would have never thought of this