-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:
01 | function changeTeams(player) |
02 | wait( 1 ) |
03 | local deadPlayer = game.Players:GetPlayerFromCharacter(player) |
04 | if deadPlayer ~ = nil then |
05 | deadPlayer.TeamColor = BrickColor.new( "Bright green" ) |
06 | end |
07 | end |
08 |
09 | function deathCheck(character) |
10 | character.Humanoid.Died:connect( function () |
11 | changeTeams(character) |
12 | end ) |
13 | end |
14 |
15 | function playerAdded(player) |
16 | player.CharacterAdded:connect(deathCheck) |
17 | end |
18 |
19 | 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.
1 | game.Players.PlayerAdded:connect( function (player) |
2 | 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. |
3 | local Humanoid = char.Humanoid |
4 | Humanoid.Died:connect( function () |
5 | player.TeamColor = [[Input Color]] -- remove the string |
6 | end ) |
7 | end ) |
8 | 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.
01 | game.Players.PlayerAdded:connect( function (player) |
02 | player.CharacterAdded:connect( function (char) |
03 | local Humanoid = char.Humanoid |
04 | Humanoid.Died:connect( function () |
05 | if game.Workspace.WhatTimeIsIt.Disabled = = true then |
06 | player.TeamColor = BrickColor.new( "Bright green" ) |
07 | else |
08 | if game.Workspace.WhatTimeIsIt.Disabled = = false then |
09 | player.TeamColor = BrickColor.new( "Medium stone grey" ) |
10 | end |
11 | end |
12 | end ) |
13 | end ) |
14 | end ) |