Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why doesn't this recognize the PlayerGui? [SOLVED]

THE REASON IS BECAUSE LOCALSCRIPTS CANNOT ACCESS OTHER'S PLAYERGUIS.

I made a 'fusion' script for a tool I'm working on and it checks a player's PlayerGui for a specific GUI first. However, the output tells me there's an 'infinite yield possible' even though I'm 100% certain the PlayerGui is there. Here is the script:

local tool = script.Parent
local player = game:GetService("Players").LocalPlayer
 
tool.Equipped:connect(function(mouse)
 
	mouse.Button1Down:connect(function()
		local ray = Ray.new(tool.Handle.CFrame.p, (mouse.Hit.p - tool.Handle.CFrame.p).unit * 300)
		local part, position = workspace:FindPartOnRay(ray, player.Character, false, true)
 
		local beam = Instance.new("Part", workspace)
		beam.Material = "Neon"
		beam.Transparency = 1
		beam.Anchored = true
		beam.Locked = true
		beam.CanCollide = false
 
		local distance = (tool.Handle.CFrame.p - position).magnitude
		beam.Size = Vector3.new(0.2, 0.2, distance)
		beam.CFrame = CFrame.new(tool.Handle.CFrame.p, position) * CFrame.new(0, 0, -distance / 2)
 
		game:GetService("Debris"):AddItem(beam, 0.1)
 
		if part then
			local humanoid = part.Parent:FindFirstChild("Humanoid")
 
			if not humanoid then
				humanoid = part.Parent.Parent:FindFirstChild("Humanoid")
			end
 
			if humanoid then
				if humanoid.Parent:FindFirstChild("FSTORM") then
					if game.Players[humanoid.Parent.Name]:WaitForChild("PlayerGui"):FindFirstChild("FuseGui") == nil then
					local gu = script.FuseGui:Clone()
					gu.Parent = game.Players[humanoid.Parent.Name].PlayerGui
					gu.Frame.Title.Text = player.Name .. " wants to fuse with you."
					local st = Instance.new("StringValue")
					st.Name = "Fuser"
					st.Value = game.Players.LocalPlayer.Name
					st.Parent = gu.Frame
					end
				end
			end
		end
	end)
end)

It's line 32 that's the problem. Please help.

1 answer

I have had this problem many times over when using :WaitForChild(""). I have found that doing either FindFirstChild() instead or doing

repeat wait() until game.Players[humanoid.Parent.Name]:FindForChild("PlayerGui"):FindFirstChild("FuseGui") ~= nil;

before your if statement. If this helped please accept this as the answer so others know it has been solved. If it doesn't fix it let me know what it says and I'll help in any way I can. If you need help with anything else feel free to ask.

6 comments

0

Now it just does nothing; no effect or error in output :/

0

Just realized I had a typo. xD Sorry. It should be ~= instead of ==

0

Hm, still no effect. Strange.

0

Also, it's supposed to be '==' because it's checking if the gui is there or not.

0

no it's supposed to be ~= xD Trust me. ~= is not equal to

0

You don't want it to be nil so we are checking that it's not nil. If you do use == it will wait until until that object is nil then stop repeating

This discussion is preserved as it was. New answers, comments, and votes are closed.