You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? Keep it simple and clear!
I want to create an admin/controller script -
What is the issue? Include screenshots / videos if possible!
The PlayerAdded/CharacterAdded event is only firing when the first player joins -
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I have already checked the devforum for solutions but I couldn’t find anything
The Script:
local Players = game:GetService("Players")
local SS = game:GetService("ServerStorage")
local Commands = require(script.Commands)
local NoiceCore = SS.NoiceCore
local adminUI = SS.NoiceCore.Admin
local values = script.Values
coroutine.wrap(function()
local function characterFunction(character)
local hum:Humanoid = character:WaitForChild("Humanoid")
local player:Player = Players:GetPlayerFromCharacter(character)
hum.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None
hum.BreakJointsOnDeath = false
local newUsernameDisplay = NoiceCore:WaitForChild("UsernameGui"):Clone()
newUsernameDisplay.Parent = character.PrimaryPart
newUsernameDisplay.Adornee = character.PrimaryPart
newUsernameDisplay:WaitForChild("Name").Text = character.Name
for i, v in pairs(character:GetChildren()) do
if v:IsA("BasePart") then
v.CollisionGroup = "Players"
end
end
hum.Died:Connect(function()
coroutine.wrap(Commands.Ragdoll)(character, 2.5)
characterFunction(character)
if values.KickOnDeath.Value == true then
player:Kick("Kick on death setting is on.")
end
end)
print(character.Name, "Character Added")
if character.Name == "wilwil_bos" then
print(character.Name, "Admin Added")
local adminPlayer = Players:GetPlayerFromCharacter(character)
local openButton = NoiceCore:WaitForChild("Open"):Clone()
local newAdminGui = nil
local newOpenGui = nil
if not adminPlayer.PlayerGui:FindFirstChild("Admin") then
local adminClone = adminUI:Clone()
adminClone.Parent = adminPlayer.PlayerGui
adminClone.Enabled = false
newAdminGui = adminClone
elseif adminPlayer.PlayerGui:FindFirstChild("Admin") then
adminPlayer.PlayerGui:FindFirstChild("Admin"):Destroy()
local adminClone = adminUI:Clone()
adminClone.Parent = adminPlayer.PlayerGui
adminClone.Enabled = false
newAdminGui = adminClone
end
if not adminPlayer.PlayerGui:WaitForChild("GameGui"):FindFirstChild("Open") then
local openClone = openButton:Clone()
openClone.Parent = adminPlayer.PlayerGui.GameGui
openClone.Visible = true
newOpenGui = openClone
elseif adminPlayer.PlayerGui:WaitForChild("GameGui"):FindFirstChild("Open") then
adminPlayer.PlayerGui:WaitForChild("GameGui"):FindFirstChild("Open"):Destroy()
local openClone = openButton:Clone()
openClone.Parent = adminPlayer.PlayerGui:WaitForChild("GameGui")
openClone.Visible = true
newOpenGui = openClone
end
game.ReplicatedStorage.Events.AdminEvent.OnServerEvent:Connect(function(player, command, info, num, secondaryInfo)
Commands.AdminFunction(command, info, player, num, secondaryInfo)
end)
end
end
function playerFunction(player)
if values:WaitForChild("KickOnJoin").Value == true then
player:Kick("This server has been locked by the owner. Please join a different server.")
end
NoiceCore:WaitForChild("AdminEvent").Parent = game:GetService("ReplicatedStorage").Events
NoiceCore:WaitForChild("FlyEvent").Parent = game:GetService("ReplicatedStorage").Events
NoiceCore:WaitForChild("UnflyEvent").Parent = game:GetService("ReplicatedStorage").Events
NoiceCore.HoldingBox.Parent = workspace
local immortal = Instance.new("BoolValue")
immortal.Name = "Immortal"
immortal.Parent = player
immortal.Value = false
print(player.Name, "Joined")
for i, v:Tool in pairs(game:GetDescendants()) do
if v:IsA("Tool") then
local handle = v:FindFirstChild("Handle")
if handle then
local touchInterest = handle:FindFirstChild("TouchInterest")
if touchInterest then
touchInterest:Destroy()
end
end
end
end
workspace.DescendantAdded:Connect(function(desc)
if desc:IsA("Tool") then
local handle = desc:FindFirstChild("Handle")
if handle then
local touchInterest = handle:FindFirstChild("TouchInterest")
if touchInterest then
touchInterest:Destroy()
end
end
end
end)
if player.Character then characterFunction(player.Character) end
player.CharacterAdded:Connect(characterFunction)
end
end)()
Players.PlayerAdded:Connect(playerFunction)
for i, v in pairs(Players:GetPlayers()) do
playerFunction(v)
end
Any help appreciated!