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

Need help with the fact a gui wont clone into the player who hit the part?

It keeps saying something is not a member of model. Just curious if there is a error somewhere?

script.Parent.Touched:connect(function(hit)
	local char = game.Players:GetPlayerFromCharacter(hit.Parent)
	 if char ~= nil then
		local repli = game:GetService("ReplicatedStorage")
		local thing = repli:WaitForChild("Knowing")
		if char.PlayerGui.Knowing == nil then
			thing:Clone().Parent = char.PlayerGui
		end
		
	end
end

2 answers

✓ Accepted answer

if x ~= nil then can be shortened to if x then. Likewise, if y == nil can be shortened to if not y then.

Furthermore, if you attempt to access a child which does not exist, an error will be produced. Instead, use Instance:FindFirstChild(string name, bool recursive = false). Thus, if char.PlayerGui.Knowing == nil then becomes if not char.PlayerGui:FindFirstChild("Knowing") then. This assumes that Knowing is a ScreenGui/BillboardGui/SurfaceGui and FE is off.

Use pla = game.Players:GetPlayerFromCharacter(hit.Parent) instead of hit.Parent:GetPlayerFromCharacter. Also, for line 7 you should be getting PlayerGui from pla, not from hit.Parent.

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