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

On Death Change Teams, [Improvement] Any help?

-This script works perfectly fine, but not the way I specifically want it to. If a player dies he changes teams :D. To the team I want! But I only want this to be able to happen during a certain time. If I copy and paste this script from server storage, it doesn't work, it has to stay in workspace. If I disable it and re-able it, it doesn't work either. I guess I am trying to say I need this script to be able to be pasted from ServerStorage into fine working conditions.

Here is the script:

function Deadesy(blabz)
wait(1)
local a = game.Players:GetPlayerFromCharacter(blabz)
if a ~= nil then
a.TeamColor = BrickColor.new("Bright green")
end end
function Livesy(KILLA)
KILLA.Humanoid.Died:connect( function() Deadesy(KILLA) end )
end
function BANOs(Playa)
Playa.CharacterAdded:connect(Livesy)
end
game.Players.PlayerAdded:connect(BANOs)

1 answer

✓ Accepted answer

This problem is simple, you need to use ServerScriptService, rather than using ServerStorage. Also, i've gone through your script and tabbed it. I also named your functions, because when going through your functions it will be allot easier to edit. If you don't understand why, I suggest reading the blog post on this website titled Clean and Tidy.

function changeTeams(player)
	wait(1)
	local deadPlayer = game.Players:GetPlayerFromCharacter(player)
	if deadPlayer ~= nil then
		deadPlayer.TeamColor = BrickColor.new("Bright green")
	end
end

function deathCheck(player)
	player.Humanoid.Died:connect(function()
		changeTeams(player)
	end)
end

function playerAdded(player)
	player.CharacterAdded:connect(player)
end

game.Players.PlayerAdded:connect(playerAdded)

Here are some links to roblox wiki pages to explain the difference between ServerStorage and ServerScriptService:

ServerScriptService

ServerStorage

2 comments

0

There are some errors in the code here. Firstly, you're connecting the CharacterAdded event to the player variable, which you should be connecting to deathCheck. Second, I would change the variable for the argument in the deathCheck function to character and reflect these changes on line 10 and 11 so that he doesn't get confused.

0

yea it didnt work

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