Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

On Death Change Teams, [Improvement] Any help?

Asked by 8 years ago

-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

Log in to vote
1
Answered by
Relatch 550 Moderation Voter
8 years ago

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

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. Spongocardo 1991 — 8y
0
yea it didnt work CarterTheHippo 120 — 8y
Ad

Answer this question