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

Help with meadows script?

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

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

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.

5 comments

0

Since it's a local script inside StarterGui, each time the player respawns that code will run.

0

Ah, I didn't realize it was in the StarterGui.

0

It's a Script in ServerScriptService and it still doesnt work :(

0

Disconnected event because of expectation.

0

I'm not sure if LocalScript run in the ServerScriptService. Put it into the StarterGui and see what happens.

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