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

[Fireserver error] Team change on death?

Asked by 4 years ago
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".

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. Trading_Opportunity 191 — 4y

2 answers

Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

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.

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. RebornedSnoop 175 — 4y
0
Thanks! RebornedSnoop 175 — 4y
Ad
Log in to vote
0
Answered by
Arxbird -5
4 years ago

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!

Answer this question