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

Character is not resetting in this script?

So basically, I was making a team change GUI and when I use it, it changes team but it won't respawn me.

Script is here

local player = game.Players.LocalPlayer

script.Parent.MouseButton1Click:connect (function()
player.TeamColor = BrickColor.new ('Neon orange')
player.LoadCharacter()
end)

I thought player.LoadCharacter() would do the trick.

3 answers

✓ Accepted answer

Hello, coolguypoopDUM!

You can't just use game.Players.LocalPlayer! You must use a LocalScript on the player/Character!

As I see, your script is on a part, so no LocalPlayer!

You can find the player that clicked simply by adding a argument for the var that you can on the click!

Edited script:

Instance.new("ClickDetector").Parent = script.Parent

script.Parent.ClickDetector.MouseClick:Connect(function(player) -- Don't use ":connect", its deprecated!
	game.Players[player.Name].TeamColor = BrickColor.new ('Neon orange')
end)

1 comment

0

Oh alright thanks!

If you want manage respawing yourself then I think you need to do a bit more more in your game script ( not local script ) to handle respawning yourself

http://wiki.roblox.com/index.php?title=API:Class/Players/CharacterAutoLoads

respawnTime = 5
Players = Game:GetService("Players")
Players.CharacterAutoLoads = false
 
Players.PlayerAdded:connect(function(Player)
	Player.CharacterAdded:connect(function(Character)
		-- find the humanoid, and detect when it dies
		local Humanoid = Character:FindFirstChild("Humanoid")
		if Humanoid then
			Humanoid.Died:connect(function()
				-- delay, then respawn the character
				wait(respawnTime)
				Player:LoadCharacter()
			end)
		end
	end)
 
	Player:LoadCharacter() -- load the character for the first time
end)

Having accomplished that you can then modify your code adding the ":" instead of period "." in your call to player:LoadCharacter()

If your code is running in a local script then

-- Assuming his is running in a local script 
local player = game.Players.LocalPlayer

script.Parent.MouseButton1Click:connect (function()
	player.TeamColor = BrickColor.new ('Neon orange')
	player:LoadCharacter()
end)

Let me know if that works, keep in mind using LoadCharacter clears out the players Backpack and PlayerGui

local player = game.Players.LocalPlayer

script.Parent.MouseButton1Click:connect (function()
player.TeamColor = BrickColor.new ('Neon orange')
player:LoadCharacter()
end)

Use a colon instead of a period when using methods.

I think the reason why you might be confused is because a programming language called Python uses period and not colons when using a method, like this:

`class Rocket(): def init(self): self.x = 0 self.y = 0

def move_up(self):
    self.y += 1

my_rocket = Rocket() print("Rocket altitude:", my_rocket.y)

my_rocket.move_up() print("Rocket altitude:", my_rocket.y)

my_rocket.move_up() print("Rocket altitude:", my_rocket.y)`

If that is why, don't be worried; just remember that Lua uses colons and not periods.

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