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

[SIMPLE] On Button Gui Click cloned Gui Doesnt Show Up?


function onmouseclick(click)
	if game.Players:FindFirstChild(click.Parent.Name) ~= nil then
		local player = game.Players[click.Parent.Name]
		if player.PlayerGui:findFirstChild("teamchange") == nil then
			local gui = game.ReplicatedStorage.teamchange:clone()
			gui.parent = player.PlayerGui
			wait (5)
			gui:Destroy()
			
		end
	end
end

script.parent.MouseButton1Click:connect(onmouseclick)


Basically what im trying to accomplish is when a user clicks the button GUI, a seperate GUI in replicated storage called teamchange is cloned and put into the user that clicked the button's PlayerGui, the output error is

14:10:22.136 - Players.BABYL0N27.PlayerGui.ScreenGui.TextButton.Script:3: attempt to index nil with 'Parent' 14:10:22.137 - Stack Begin 14:10:22.138 - Script 'Players.BABYL0N27.PlayerGui.ScreenGui.TextButton.Script', Line 3 - function onmouseclick 14:10:22.138 - Stack End

The script is a normal game script with a parent of a text button which is under a ScreenGui.

Thanks for any help.

1 answer

✓ Accepted answer

The MouseButton1Click event returns nil, you can't get the player from it. So you should either use a Local Script and fire a RemoteEvent when they click the button, or.. Since your script is inside PlayerGui, you could use script.Parent's until you reach the player.

2 comments

0

Appreciate the suggestion, was able to find the Player from the script.parent.parent.parent and thus make the script work. Thanks!

0

No problem.

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