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

how can i stop a script that edits a character from repeating every time a new player joins?

i added a script i found on google to my game to replace character model names however it repeats every time a new player joins which would constantly respawn a player, how can i fix this?

game.Players.PlayerAdded:Connect(function(player)
	local ignore = false
	player.CharacterAdded:connect(function(oldCharacter)
		wait(1)
		if ignore then return end
		ignore = true
		spawn(function()
			player.Character = nil
			oldCharacter.Archivable = true
			local newCharacter = oldCharacter:Clone()
			newCharacter.Name = player.PlayerNameValue.Value
			player.Character = newCharacter	
			newCharacter.Parent = workspace
			if newCharacter:FindFirstChildOfClass("ForceField") then
				while oldCharacter:FindFirstChildOfClass("ForceField") do
					oldCharacter.ChildRemoved:wait()
				end
				repeat
					local forcefield = newCharacter:FindFirstChildOfClass("ForceField")
					if forcefield then forcefield:Destroy() end
				until not forcefield
			end
			ignore = false 
		end)
	end)
end)

3 comments

0

Maybe use break

0

@LinkTheHero what you can do is place a script in StarterCharacterScripts. Scripts in here will be automatically cloned and placed into the character making is so that everytime a character spawns it will run the code.

0

move 'ignore' outside of both functions

1 answer

Delete line 2 'local'.

Local is a thing that unable to change so you have to delete it for creating a changeable variable.

Comment below if you keep having problems, I just find that out :V

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