Why doesn't my script work?

script:
local keycard = workspace.Technical.KeyCard1.ClickBox.ClickDetector

PlayerGui = game:GetService(“Players”):WaitForChild(“LocalPlayer”):WaitForChild(“PlayerGui”)

local kv = false

keycard.MouseClick:Connect(function()

PlayerGui:WaitForChild(“GUI”):WaitForChild(“KeyCardGetText”).Visible = true

if kv == false then

kv = true

keycard.Parent.Parent.Parent.KeyCard1:Destroy()

end

task.wait(3)

PlayerGui:WaitForChild(“GUI”):WaitForChild(“KeyCardGetText”).Visible = false

end)

local ts = game:GetService(“TweenService”)

local wall = game.Workspace.Technical.Secret_Wall

local ti = TweenInfo.new (

5,

Enum.EasingStyle.Sine,

Enum.EasingDirection.Out

)

local goal = {Position = Vector3.new(wall.Position.X, wall.Position.Y +7, wall.Position.Z)}

local tween = ts:Create(wall, ti, goal)

game.Workspace.Technical.CardReader.ClickBox.ClickDetector.MouseClick:Connect(function()

if kv == true then

tween:Play()

task.wait(6)

game.Workspace.Technical.ElevatorWall.CanCollide = false

print(“tween played”)

else

PlayerGui:WaitForChild(“GUI”):WaitForChild(“NoKeyCardText”).Visible = true

task.wait(4)

PlayerGui:WaitForChild(“GUI”):WaitForChild(“NoKeyCardText”).Visible = false

end

end)
it checks if the player got a keycard, if they didn’t, it makes UI appear, if they did, the tween plays. no error, only “Infinite yield possible on ‘Players:WaitForChild(“LocalPlayer”)’”

1 Like

you cant do :WaitForChild(“LocalPlayer”) because its a read only properity

1 Like

You dont have to check if the localplayer exists.

1 Like

If you really want to check if local player exists, you should do it like this:

game.Players:WaitForChild(game.Players.LocalPlayer.Name)
1 Like

Thanks to everyone! i didn’t have to check if localplayer exists.

Mark the reply that solved it as solution if it worked for you.