Hello! So I have a server script that manages everything and if a specific player joins the game, he will be given special benefits. The part that doesn’t work is this chunk that sees if the player’s name is not the special one, then it will kick them from the game.
Code:
if Player.Name == "TabbyCat904" then
print("Player found. Hello, WolfieGamerYT!")
ServerStorage.SpeedTool:Clone().Parent = Player.Backpack
print("tool given")
Player.leaderstats.Coins.Value = 1000000
Player.leaderstats.Gems.Value = 1000000
else
local EnemyHumanoid = Character:WaitForChild("Humanoid")
if EnemyHumanoid then
print("humanoid found")
while true do
task.wait(1)
EnemyHumanoid:TakeDamage(5)
EnemyHumanoid.Died:Connect(function()
Player:Kick("Be gone, none me!")
end)
end
end
If you think you know what went wrong, please let me know. Have a wonderful day!
You are connecting the died event every second which is not necessary, this will cause a memory leak. Additionally checking for a special user you should rather use UserId than the username.
local PlayerService = game:GetService("Players")
local ServerStorage = game:GetService("ServerStorage")
PlayerService.PlayerAdded:Connect(function(Player)
if Player.UserId == 0000000000 --[[USER ID HERE]] then
local SpeedTool = ServerStorage.SpeedTool:Clone()
SpeedTool.Parent = Player.Backpack
local Stats = Player:WaitForChild("leaderstats")
Stats.Coins.Value = math.huge
Stats.Gems.Value = math.huge
else
local Character = Player.Character
local Humanoid = Character:WaitForChild("Humanoid")
Humanoid.Died:Connect(function()
Player:Kick("Be gone!")
end
while task.wait(1) do
Humanoid:TakeDamage(5)
end
end
end
@Kittylitterking123 I’ve made some changes to the code. Let me know if it works now. Make sure you replace the numbers with the UserID you want to have the abilities.
Players.PlayerAdded:Connect(function(Player)
Player.CharacterAdded:Connect(function(Character)
repeat wait() until Character:FindFirstChild("Head") -- This is just to give the player a nametag above their head, just ignore it lol
local newNametag = Nametag:Clone()
newNametag.Parent = Character.Head
newNametag.Adornee = Character.Head
newNametag.TextLabel.Text = Player.DisplayName
task.wait()
if Player.UserId == "3081295884" then
print("Player found. Hello, WolfieGamerYT!")
local SpeedTool = ServerStorage.SpeedTool:Clone()
SpeedTool.Parent = Player.Backpack
print("tool given")
local Stats = Player:WaitForChild("leaderstats")
Stats.Coins.Value = math.huge
Stats.Gems.Value = math.huge
else
local Humanoid = Character:WaitForChild("Humanoid")
while task.wait(1) do
Humanoid:TakeDamage(5)
if Humanoid.Health == 0 then
break
end
end
Player:Kick("Begone!")
end
end)
end)