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

Get the character without using a function?

I am trying to make this so that the script runs when the server is created and then when after some settings have been changed it disables some spawn bricks. My issue is when the player dies it seems the loop runs twice renabling my spawn locations. Is there any way to kill a player without using the function like I am using below?

game.Players.PlayerAdded:connect(function(player)
player.CharacterAdded:connect(function(char)
while true do
	local childs = game.Workspace.Map1:GetChildren()
	for i,v in pairs(childs) do 
		if v.ClassName == "SpawnLocation" then
		v.Enabled = true
		
		end
		end
	char:BreakJoints()
	wait(15)
	local childs = game.Workspace.Map1:GetChildren()
	for i,v in pairs(childs) do 
		if v.ClassName == "SpawnLocation" then
		v.Enabled = false
		end
end
	local childs = game.Workspace.Map2:GetChildren()
	for i,v in pairs(childs) do 
		if v.ClassName == "SpawnLocation" then
		v.Enabled = true
		end
	end
	
	char:BreakJoints()
	end
end)
end)

1 answer

✓ Accepted answer

Your problem is the infinite loop nested inside two reoccuring events.

What exactly are you trying to do with this code? Don't tell me what you want the code to do, but rather the intent behind it. Are you trying to make individual Players' spawns disabled?

2 comments

0

Well kinda what you said. I have several spawn locations located inside a model and so my intent is that this script over in this case 15 seconds will disable a set of spawn locations and renable another set as well as kill the player. As I noticed once the player dies my character function repeats and then theres 2 loops running at once.

1

There will be another loop spawned each time a Player dies. any player, because of how this is written. If you want per-player Spawns to work, you'll have to make a custom spawning function, and call it each time a Player dies.

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