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

[Fireserver error] Team change on death?

local RemoteEvent = game.ReplicatedStorage.ChangeTeam

local Humans = "Dark blue"
local Zombies = "Really red"

game.Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(character)
        character:WaitForChild("Humanoid").Died:Connect(function()
            print(player.Team.Name)
            if player.Team.Name == "Blue" then
                RemoteEvent:FireServer(BrickColor.new(Zombies))
            else
                RemoteEvent:FireServer(BrickColor.new(Humans))
                wait(0.5)
            end
        end)
    end)
end)

This is inside a script. The point is that when a player dies it changes to an opposite team , in this case blue to red , vice versa.

When I die the output says this "FireServer can only be called from the client".

1 comment

0

:FireServer is used for local scripts, :FireAllClients() is used for normal scripts the both are the same thing. Just make sure you are using the right one.

2 answers

✓ Accepted answer

Local Script

local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer
local Character = LocalPlayer.Character or LocalPlayer.CharacterAdded:wait()

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TeamChangeRemote = ReplicatedStorage.TeamChange

Character:WaitForChild("Humanoid").Died:Connect(function()
  if LocalPlayer.Team.Name == "Humans" then
  TeamChangeRemote:FireServer('zombie')
   else
  TeamChangeRemote:FireServer('human')
  end
end)

Server Script

local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Teams = game:GetService("Teams")

local TeamChangeRemote = ReplicatedStorage.TeamChange

TeamChangeRemote.OnServerEvent:Connect(function(Player, TeamName)
 for _,TeamEntitys in next, Teams:GetChildren() do
    if (TeamEntitys.Name:lower()):find(TeamName:lower()) then
        Player.Team = TeamEntitys
      end
    end
  return nil
end)

Instructions

  1. Create two teams with one called human & zombie
  2. Place the local script in StarterCharacterScripts
  3. Place the server script in ServerScriptService

I hope this answers your needs.

2 comments

0

I thought it didnt work but I changed the typo then it worked. The typo is " if LocalPlayer.Team.Name == "Humans" then" the team is called human not humans.

0

Thanks!

Hey! :FireServer cant be used on a server script. :FireServer fires a remote event from the client to the server. Since this script is in a server, you can take the code that is in the remote event from your server script, or you can make a function above the PlayerAdded event, and then fire that function in the if statment. Hope this helped!

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