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

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

Asked by 8 years ago

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

0
this is very confusing, because you set all of your parameters/arguments to player. woodengop 1134 — 8y
1
fixed it so it works but, Cant past from server sotrage CarterTheHippo 120 — 8y
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. BlackJPI 2658 — 8y
0
Is there a way to make it so that if your on a certain team and you die, you change to another CarterTheHippo 120 — 8y
View all comments (3 more)
0
I could help, but That would mean i'd have to re-write it. woodengop 1134 — 8y
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 CarterTheHippo 120 — 8y
0
I found your main problem (Edited Answer) woodengop 1134 — 8y

2 answers

Log in to vote
0
Answered by
woodengop 1134 Moderation Voter
8 years ago

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!

0
so if i paste this from server storage It works? Lets find out. CarterTheHippo 120 — 8y
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. CarterTheHippo 120 — 8y
0
posted what i did below and it works CarterTheHippo 120 — 8y
0
ill accept your answer because it lead me too my conclusion CarterTheHippo 120 — 8y
Ad
Log in to vote
0
Answered by 8 years ago

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)
0
this script stays in workspace and does not move out of it. CarterTheHippo 120 — 8y

Answer this question