hi there i am making a staff only area is there any way i can make this script kick people out of the game if they come in
local player = game:GetService("Players")
function onTouch(hit)
if game.Players:FindFirstChild(hit.Parent.Name) ~= nil then
local char = game.Players:FindFirstChild(hit.Parent.Name)
local name = char
char:Kick("You have been kicked for entering a Staff Area.")
script.Parent.Touched:Connect(onTouch)
local peopleWhoCanEnter = {'name1', 'name2', 'name3'} -- names of the people who can enter the room
function onTouch(hit)
if game.Players:FindFirstChild(hit.Parent.Name) then -- checks if it's a player
if not peopleWhoCanEnter[hit.Parent.Name] then -- if the player doesn't have access it kicks them
game.Players[hit.Parent.Name]:Kick("You have been kicked for entering a Staff Area.")
end
end
end
script.Parent.Touched:Connect(onTouch)```
Yes, you’d do this if game.Players[hit.Parent.Name]:GetRankInGroup(groupId) < rankNumber then
instead of if not peopleWhoCanEnter[hit.Parent.Name] then
GetRoleInGroup Returns a string of the current role the person is in in the group or Guest if they aren’t in the group, the proper method is GetRankInGroup.
Also, game.Players:FindFirstChild(hit.Parent.Name) would better of being as game:GetService("Players"):GetPlayerFromCharacter(hit.Parent) and storing it in a variable since you use it more than once
This would be a bettter approach if you just want the door’s purpose to be kicking low ranked people
local allowedRank = 3
local function onTouch(hit)
local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
if not player or player:GetRankInGroup(GROUPID) <= allowedRank then
return
end
player:Kick("You have been kicked for entering a Staff Area.")
end
script.Parent.Touched:Connect(onTouch)
Oh right, my mistake, use > instead of <= if you don’t want to allow the rank with the number3 either, otherwise if you want to allow the rank with the number 3 in, use >=
local players = game:GetService('Players')
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local player = players:GetPlayerFromCharacter(hit.Parent)
if not player:GetRankInGroup(--[[group id here]]) >= 4 then
player:Kick('Message here')
end
end
end)