Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
Lyphios 77
4 years ago

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

0
You also use CreatorId Geobloxia 251 — 4y

2 answers

Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

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!

0
Thanks for the step by step! I'll see if it works, it looks promising. Lyphios 77 — 4y
0
indenting! my eyes! great answer, though turtle2004 167 — 4y
0
If you can, accept it so others know that the question is answered maumaumaumaumaumua 628 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

@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.

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. maumaumaumaumaumua 628 — 4y
0
... PrismaticFruits 842 — 4y

Answer this question