I want to make it to where if you click a part, the gui would go away/ destroyed. My current script doesn't work. Here it is:
1 | function onClicked(playerWhoClicked) |
2 | local guiName = game.LocalPlayer.PlayerGui.GameName -- Game name gui |
3 | wait( 0.1 ) |
4 | guiName:Destroy() |
5 | end |
6 |
7 | script.Parent.ClickDetector.MouseClick:connect(onClicked) |
The error says:
**LocalPlayer is not a valid member of DataModel
Help?
First off, to use "LocalPlayer", you need to be looking in players. Example:
1 | local player = game.Players.LocalPlayer -- NOT just game.LocalPlayer |
Second of all, I do recommend making this work using remote events. However, here is what I believe you need to do
1 | function onClicked(playerWhoClicked) |
2 | local guiName = playerWhoClicked.PlayerGui.GameName -- Game name gui, assuming everything is spelled correctly |
3 | if guiName ~ = nil then -- just making sure it's there |
4 | wait() -- There is no point of waiting 1/10 seconds, just give it a wait() so it catches up. |
5 | guiName:Destroy() --now it's removed |
6 | end -- an extra end is now added |
7 | end |
8 |
9 | script.Parent.ClickDetector.MouseClick:connect(onClicked) |
LocalPlayer is a child of Players
Use game.Players.LocalPlayer instead.
LocalPlayer is not a valid member of DataModel like it says. It should be game.Players.LocalPlayer, not just game.LocalPlayer