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

Does not remove the gui from selected players?

Asked by 7 years ago

I want to remove this ScreenGUI from selected Players but it does not work. The code is below.

plr = script.Parent.Parent.Parent
admins = {"AdvancedCode", "Player1"}

d = false

for i = 1, #admins do
if plr.Name == admins[i] then
script.Parent:remove()

if not d then
d = true
end
end
end

All help is appreciated!

1 answer

Log in to vote
1
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
7 years ago
Edited 7 years ago

You should use a LocalScript - so you can index game.Players.LocalPlayer to retrieve the client easily.

Code would look like this;

local plr = game.Players.LocalPlayer --This is the player!
local admins = {"AdvancedCode", "Player1"}
local d = false

for i = 1, #admins do
    if plr.Name == admins[i] then
        script.Parent:Destroy() --'remove' is deprecated. Use Destroy!
        d = true;
        break --break the current loop
    end
end

Assuming the script's Parent is the gui, this should work.

0
Added a modicum amount of code to this to make it a little bit easier to manipulate, I appreciate this! AdvancedCode 136 — 7y
0
Glad I could help :) Happy developing! Goulstem 8144 — 7y
Ad

Answer this question