-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.
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!
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)