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

Team change on death [Fixed but still need help] Any help?

-I am wanting this script to be able to be copy and pasted from ServerStorage into workspace and work perfectly fine.

Here is the Script:

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(character)
	    character.Humanoid.Died:connect(function()
	        changeTeams(character)
	    end)
	end
	 
	function playerAdded(player)
	    player.CharacterAdded:connect(deathCheck)
	end
	 
	game.Players.PlayerAdded:connect(playerAdded)

-I got the script to work, but I cant however make it work after pasting it from server storage or disabling and undisabling it.

7 comments

0

this is very confusing, because you set all of your parameters/arguments to player.

1

fixed it so it works but, Cant past from server sotrage

0

You can't paste this script into Workspace. The Event PlayerAdded only fires once per player, and that's when they first enter. When you copy it, that event needs to fire again before it will work.

0

Is there a way to make it so that if your on a certain team and you die, you change to another

0

I could help, but That would mean i'd have to re-write it.

1

You can just explain me what to write where and ill rewrite it :p But if you rewrite it and it works I can accept your answer

0

I found your main problem (Edited Answer)

2 answers

✓ Accepted answer

As I said if I am going to answer, i'm gonna re-write it. Do note that your hierarchy was a bit confusing, making it hard to examine.

game.Players.PlayerAdded:connect(function(player) 
	player.CharacterAdded:connect(function(char) -- characterAdded, I know that you can access the character property, but I'm really used to CharacterAdded, feel free to change.
		local Humanoid = char.Humanoid
		Humanoid.Died:connect(function()
			player.TeamColor = [[Input Color]] -- remove the string
		end)
	end)
end)

This code provided is 8 lines long, and Very clear to understand( if you are familiar with rbx.lua ).

Edited: I found your main problem! Scripts don't run in ServerStorage, use ServerScriptService instead!

4 comments

0

so if i paste this from server storage It works? Lets find out.

0

doesnt seem so, but I feel into a breakthrough of what I wanted, and I am working on it right now, your script may have made it easier for me to do it. If it doesnt work I will post another question.

0

posted what i did below and it works

0

ill accept your answer because it lead me too my conclusion

This is what I did, and its what i wanted. In my game I change whether a certain script is disabled or not and this script detects that so i can change the team you go to at certain times.

game.Players.PlayerAdded:connect(function(player)
	    player.CharacterAdded:connect(function(char) 
	        local Humanoid = char.Humanoid
	        Humanoid.Died:connect(function()
		if game.Workspace.WhatTimeIsIt.Disabled == true then
	            player.TeamColor = BrickColor.new("Bright green")
		else
			if game.Workspace.WhatTimeIsIt.Disabled == false then
	            player.TeamColor = BrickColor.new("Medium stone grey")
			end
			end 
	        end)
	    end)
	end)

1 comment

0

this script stays in workspace and does not move out of it.

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