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

20:16:23.646 - Part is not a valid member of Workspace ?

local player = game:GetService("Players").LocalPlayer
workspace.Part:FindFirstChild("ClickDetector").MouseClick:Connect(function()
	local oGUI = script:FindFirstChild("ScreenGui")
	     if oGUI then
		local GUI = oGUI:Clone()
		GUI.Parent = player.PlayerGui
	end
end)

Im trying to create a local script where if you click a 'Part' , the GUI appears , the script is in replicated storage and the GUI is the child of the script , but for some reason when i do the workspace.Part thing it only says 20:16:23.646 - Part is not a valid member of Workspace I Tried doing it with FindFirstChild as well

workspace:FindFirstChild("Part").ClickDetector.MouseClick:Connect(function()
	local oGUI = game.ReplicatedStorage.ScreenGui
	     if oGUI then
		local GUI = oGUI:Clone()
		GUI.Parent = player.PlayerGui
	end
end)

But it only says 20:38:23.165 - ReplicatedFirst.LocalScript:3: attempt to index nil with 'ClickDetector' , can anybody help me please ?

3 answers

You have to use :WaitForChild() because in the meantime, the part or clickdetector isn't loaded yet while the script does. Also I believe this must be in ReplicatedFirst and not in ReplicatedStorage incase. But you can use a Script instead of a LocalScript and have it inserted in ServerScriptStorage. To get the player you can use the PlayerAdded event:

game.Players.PlayerAdded:Connect(function(player)
    workspace:WaitForChild("Part"):WaitForChild("ClickDetector").MouseClick:Connect(function()
        local oGUI = script:WaitForChild("ScreenGui")
        if oGUI then
	    local GUI = oGUI:Clone()
	    GUI.Parent = player.PlayerGui
        end
    end)
end)

Is there a reason why your script is in replicatedfirst? Because of replication order, things in ReplicatedFirst replicate before anything else. By the time the script's loaded, the part isn't loaded in yet. You should probably move your script unless it HAS to be in ReplicatedFirst/

This is a simple solution, but...

Make sure there is a ClickDetector object in your part.

Also, I would move the script into StarterGui. (Going back to what @iiMegabyteGaming said.)

Edit: Don't move the Script into StarterGui unless you move the Gui to something like replicated storage or lighting.

2 comments

0

Don't move it to StarterGui otherwise the ScreenGui will be seen, he only wants it to be shown once he clicks.

0

Oh right, the ScreenGui is a child of the script.

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