Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Help with deleting a gui by clicking on a part?

Asked by 7 years ago

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:

function onClicked(playerWhoClicked)
    local guiName = game.LocalPlayer.PlayerGui.GameName -- Game name gui
    wait(0.1)
    guiName:Destroy()
end

script.Parent.ClickDetector.MouseClick:connect(onClicked)

The error says:

**LocalPlayer is not a valid member of DataModel

Help?

3 answers

Log in to vote
3
Answered by 7 years ago

First off, to use "LocalPlayer", you need to be looking in players. Example:

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

function onClicked(playerWhoClicked)
    local guiName = playerWhoClicked.PlayerGui.GameName -- Game name gui, assuming everything is spelled correctly
if guiName ~= nil then -- just making sure it's there
    wait() -- There is no point of waiting 1/10 seconds, just give it a wait() so it catches up.
    guiName:Destroy() --now it's removed
end -- an extra end is now added
end

script.Parent.ClickDetector.MouseClick:connect(onClicked)

0
Hope I helped! Please mark as answered if I did iamnoamesa 674 — 7y
0
The wait is pointless but the rest looks OK. User#11440 120 — 7y
0
Yeah I've always been told that. The wait() is really useless unless in a loop. But it's a personal preference, I for whatever reason think it helps iamnoamesa 674 — 7y
0
It doesn't. User#11440 120 — 7y
0
Alright thanks for the tip iamnoamesa 674 — 7y
Ad
Log in to vote
1
Answered by
Sur4y 40
7 years ago

LocalPlayer is a child of Players

Use game.Players.LocalPlayer instead.

Log in to vote
0
Answered by 7 years ago

LocalPlayer is not a valid member of DataModel like it says. It should be game.Players.LocalPlayer, not just game.LocalPlayer

Answer this question