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

Character is not resetting in this script?

Asked by 6 years ago

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

Log in to vote
0
Answered by
Leamir 3138 Moderation Voter Community Moderator
6 years ago

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)

0
Oh alright thanks! P_sychik 7 — 6y
Ad
Log in to vote
0
Answered by 6 years ago

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

Log in to vote
-1
Answered by 6 years ago
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.

Answer this question