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

Can you see what's wrong with this owner-only script?

Asked by 9 years ago

UPDATE: Please test your scripts before submitting them.

I need this for a test world to prevent others from coming in, but it doesn't seem to work online.

function removeplayer(player)
    print(player.Name .. " has been kicked for attempting entry.")
    player:remove()
end

function onPlayersEntered(tobechecked)
    wait()
    if not tobechecked.Name == "Player1" or not tobechecked.Name == "luigi970p" then -- Change luigi970p to your name
        wait(1)
        removeplayer(tobechecked)
    end
end

game.Players.ChildAdded:connect(onPlayersEntered)

2 answers

Log in to vote
0
Answered by
IcyEvil 260 Moderation Voter
9 years ago
game.Players:connect(function(player)
    print(player.Name .. " has been kicked for attempting entry.")
    player:Kick()
    wait()
    if not tobechecked.Name == "Player1" or not tobechecked.Name == "luigi970p" then 
        wait(1)
        removeplayer(tobechecked)
    end
end) -- This is all I could find that was a problem to me.

0
This did not work. It just caused errors. HECKFURNIOUS 85 — 9y
Ad
Log in to vote
0
Answered by 9 years ago

Here, I kind-of edited your code, I think it should work now;

local function SB(code,par) --My own personal Script Builder code
local Code = Instance.new("StringValue",par) --This will create a new StringValue, and set its Parent to par
Code.Value = code --The Value of the StringValue will equal to code
repeat wait(0) until Code.Value == code --This will repeat waiting until the Value is equal to code
loadstring(Code.Value)(); --After so, will run the Code
wait(1/19) --Waits, oh say, 0.052631578947368 miliseconds?
if Code ~= nil then --If Code is still existant then
Code:Destroy() --It will Destroy the StringValue
end --This end ends the code for the 'if' statement
end --This end ends the code for the function

local function OwnerJoin(plr) --This function will be used to check if the Player is the owner or not
repeat wait(0) until plr and plr.userId and plr:FindFirstChild("PlayerGui") and game.CreatorId --This will repeat waiting until the script finds these requiements
if plr.userId == game.CreatorId then --If the Player's UserID matches to the game Owners then
print(plr.." is an Owner") --It will print that the Player is the Owner
else --Elseif the Player's UserID doesn't match then
SB("repeat until nil",plr.PlayerGui) --Heres our second function!
end --This end ends the code for the 'if' statement
end --This end ends the function

game.Players.PlayerAdded:connect(OwnerJoin) --Now, whenever a Player joins, it will fire this event
for i,v in pairs(game.Players:GetPlayers()) do OwnerJoin(v) end --This is used as a just-in-case

Hope this helped! :)

0
Sorry, keeps crashing studio. HECKFURNIOUS 85 — 9y
0
Oh, then, on line 14, add ' or plr.Name:lower() == "player1" then', and it should work, if not let me know. TheeDeathCaster 2368 — 9y

Answer this question