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

Help with meadows script?

Asked by 10 years ago

I've been trying to make this script. It's supposed to check if the player's deaths == 11 and then changes their team to Spectators, and respawns them.

player = game.Players:WaitForChild("LocalPlayer")

if player.leaderstats.deaths.Value == 11 then
    player.TeamColor = BrickColor.new("White")
    player:LoadCharacter()
end

2 answers

Log in to vote
0
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
10 years ago

LocalPlayer is a property, not a child, of Players. You cannot WaitForChild it, because there is no "LocalPlayer" child.

In addition, you never need to wait for LocalPlayer.

player = game.Players.LocalPlayer
Ad
Log in to vote
-1
Answered by 10 years ago

In addition to what BlueTaslem said, you only run the script/function once. You need to continually wait until the Player's deaths become equal to 11. This would work:

local player = game.Players.LocalPlayer

function checkDeaths()
    if player.leaderstats.deaths.Value == 11 then
        player.TeamColor = game.Teams.Lobby.TeamColor
        player:BreakJoints()
    end
end

player.leaderstats.deaths.Changed:connect(checkDeaths) --This runs the function every time the player's death value changes. Alternatively, you can use "player.Died:connect(checkDeaths)", although I suggest the original.
0
Since it's a local script inside StarterGui, each time the player respawns that code will run. Perci1 4988 — 10y
0
Ah, I didn't realize it was in the StarterGui. SlickPwner 534 — 10y
0
It's a Script in ServerScriptService and it still doesnt work :( BosswalrusTheCoder 88 — 10y
0
Disconnected event because of expectation. BosswalrusTheCoder 88 — 10y
0
I'm not sure if LocalScript run in the ServerScriptService. Put it into the StarterGui and see what happens. SlickPwner 534 — 10y

Answer this question