Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I make the Owners of the game spawn in a different place?

I made this script to make the owner's spawn location different from the players, the problem is, nothing happens. I spawn in the regular neutral spawn point.

Owner = {"Liphios","XxTameMexX"}
function isAllowed(name)
for i,child in pairs(Owner) do
if string.lower(child) == string.lower(name) then
return true
end
end
return false
end

function onPlayerAdded(newPlayer)
if isAllowed(newPlayer.Name) and newPlayer:findFirstChild("Humanoid") ~= nil then
Owner.SpawnLocation = (0,90,0)
end
end

workspace.ChildAdded:connect(onPlayerAdded)

Can someone show me where I went wrong or something? Please and thanks

1 comment

0

You also use CreatorId

2 answers

✓ Accepted answer

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")
--// GetService since it can be renamed.

function PlayerAdded(Player)

end

Players.PlayerAdded:Connect(PlayerAdded) --// We connect the PlayerAdded event

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"}
--// Add an array of names

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 --// Basically loop for every name

if string.lower(name) == string.lower(Username) then

return true --// Return true if it's in the list

end

end

return false --// If it's not in the list return false

end

Now that we have our function we'll script the PlayerAdded function

function PlayerAdded(Player)

local IsOwner = Check(Player.Name) --// Check if the player is in the list
 
if IsOwner then

--// Set the spawn location

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")

--// GetService since it can be renamed.

function Check(Username)

for _,name in next,Owners do --// Basically loop for every name

if string.lower(name) == string.lower(Username) then

return true --// Return true if it's in the list

end

end

return false --// If it's not in the list return false

end

function PlayerAdded(Player)

local IsOwner = Check(Player.Name) --// Check if the player is in the list
 
if IsOwner then

--// Set the spawn location

Player.RespawnLocation = SpawnLocation

end

end

Players.PlayerAdded:Connect(PlayerAdded) --// We connect the PlayerAdded event

Done! If this answered your question, accept the answer!

3 comments

0

Thanks for the step by step! I'll see if it works, it looks promising.

0

indenting! my eyes! great answer, though

0

If you can, accept it so others know that the question is answered

@maumaumaumaumaumua's answer is correct and everything but I suggest insiead of using names use: player.UserId because exploiters can easily rename themselves, so use used Ids instead.

2 comments

0

Renaming a player objects would result in an error, even if they manage to change it the server would still have the name before being changed on the client.

0

...

This discussion is preserved as it was. New answers, comments, and votes are closed.