Problem with adding sounds to my planekit

I’m trying to add sounds to my planekit (sleitnicks planekit)

And the code doesn’t work


while true do
	if script.Parent.Parent.Parent.Parent ~= game.Workspace.PlaneKit then
		plr = game.Players:GetPlayerFromCharacter(script.Parent.Parent.Parent.Parent)
		gui = plr:WaitForChild("PlayerGui"):WaitForChild("PlaneGui")
		--speed = tonumber(gui.Pannel.Speed.Value.Text)
		script.Parent.Sound.Playing = true
		--script.Parent.Sound.Pitch = (speed)/2
	end
	wait(.1)
end

The whole script

:WaitForChild("PlaneGui")

The issue is at this part of the code
It doesn’t work because the PlaneGui parents itself to the PlayerGui later than the code executes.

How to fix this?

1 Like

What error are you getting in the output?

That isn’t preventing it from working. WaitForChild will continue yielding until that child exists. If it’s never resolving then your ScreenGui isn’t named “PlaneGui”.

20210513_101359 thats the weird thing it is named planegui

And there is also nothing in the output

Make sure plr exists first to ensure the problem isn’t with waiting for PlayerGui.

plr = game.Players:GetPlayerFromCharacter(script.Parent.Parent.Parent.Parent)

if plr then
    gui = plr:WaitForChild("PlayerGui"):WaitForChild("PlaneGui")
end

If that’s not the problem then double check the PlaneGui’s name for a trailing space character. Try rewriting the name, and copy pasting that into the string in the WaitForChild. I’ve encountered issues with studio adding invisible characters to string Attributes, which might be what’s happening here.