This is a bit messy, first i would not recommend you to use workspace.ChildAdded for the player added function, this would be used every child added into the workspace, also, :connect is deprecated and shouldn't used for new work, use :Connect instead.
So, instead of ChildAdded in workspace use PlayerAdded in the Players Service.
local Players = game:GetService("Players")
function PlayerAdded(Player)
end
Players.PlayerAdded:Connect(PlayerAdded)
So we have it connected, now since this is just the connection, we have to add your code to it, but a little better
So first we'll add the Owners Array at the beginning
local Owners = {"Name1","Name2"}
Now that we have that done we'll make a function to check if they are in the list or not
function Check(Username)
for _,name in next,Owners do
if string.lower(name) == string.lower(Username) then
return true
end
end
return false
end
Now that we have our function we'll script the PlayerAdded function
function PlayerAdded(Player)
local IsOwner = Check(Player.Name)
if IsOwner then
Player.RespawnLocation = SpawnLocation
end
end
Since we don't have a SpawnLocation defined, you have to put a spawn location and define it, And that's it, this is the final code
local Owners = {"Name1","Name2"}
local Players = game:GetService("Players")
function Check(Username)
for _,name in next,Owners do
if string.lower(name) == string.lower(Username) then
return true
end
end
return false
end
function PlayerAdded(Player)
local IsOwner = Check(Player.Name)
if IsOwner then
Player.RespawnLocation = SpawnLocation
end
end
Players.PlayerAdded:Connect(PlayerAdded)
Done! If this answered your question, accept the answer!
1 comment
You also use CreatorId