ive been trying to make it so it fires for a specific team’s only clients but it only fires for the specific team’s client that dies.
please help me fix this annoying bug!
i got a script in startercharacterscripts that fires a remoteevent to the client and the localscript receives it and fires the remoteevent to the server and then the server checks if the player is on the specific team or not.
server script:
game:GetService("ReplicatedStorage").Events2.CombineDead.OnServerEvent:Connect(function(player)
if player.TeamColor == BrickColor.new("Black") then
print("ok")
local ok = screengui:Clone()
ok.Parent = player.PlayerGui
ok.Enabled = true
ok.TextLabel.Text = "Officer "..player.Name.." is down."
--ok.TextLabel.Position = UDim2.new(-5 + math.sin(tick())/13,0,-5 + math.sin(tick())/13,0)
local function randomSound()
local SoundList = game.ServerStorage.Combine.SoundList:GetChildren()
local randomNumber = math.random(1, #SoundList)
for i, v in pairs(SoundList) do
if i == randomNumber then
local sound = v:Clone()
sound.Parent = ok
sound:Play()
wait(10)
ok:Destroy()
end
end
end
randomSound()
else
warn(player.Name.." is not a combine!!!")
end
end)
You cannot fireallclients from a localscript. If I were you, I would just iterate through the Players in the server script and check their team. If in the right team, the script will proceed to do whatever it is that you want it to do.
here you are checking if the player’s team == “Black” and not if the player’s team is the same as the team of the player who died.
You should add a parameter or some way to check which team the player is in who died and compare it to that team.
game:GetService("ReplicatedStorage").Events2.CombineDead.OnServerEvent:Connect(function(player)
if player.TeamColor == BrickColor.new("Black") then
print("ok")
local ok = screengui:Clone()
ok.Parent = player.PlayerGui
ok.Enabled = true
ok.TextLabel.Text = "Officer "..player.Name.." is down."
--ok.TextLabel.Position = UDim2.new(-5 + math.sin(tick())/13,0,-5 + math.sin(tick())/13,0)
local function randomSound()
local SoundList = game.ServerStorage.Combine.SoundList:GetChildren()
local randomNumber = math.random(1, #SoundList)
for i, v in pairs(SoundList) do
if i == randomNumber then
local sound = v:Clone()
sound.Parent = ok
sound:Play()
wait(10)
ok:Destroy()
end
end
end
randomSound()
else
warn(player.Name.." is not a combine!!!")
end
end)
that would result in:
game:GetService("ReplicatedStorage").Events2.CombineDead.OnServerEvent:Connect(function(player, playerWhoDied)
if player.TeamColor == playerWhoDied.TeamColor then
print("ok")
local ok = screengui:Clone()
ok.Parent = player.PlayerGui
ok.Enabled = true
ok.TextLabel.Text = "Officer "..player.Name.." is down."
--ok.TextLabel.Position = UDim2.new(-5 + math.sin(tick())/13,0,-5 + math.sin(tick())/13,0)
local function randomSound()
local SoundList = game.ServerStorage.Combine.SoundList:GetChildren()
local randomNumber = math.random(1, #SoundList)
for i, v in pairs(SoundList) do
if i == randomNumber then
local sound = v:Clone()
sound.Parent = ok
sound:Play()
wait(10)
ok:Destroy()
end
end
end
randomSound()
else
warn(player.Name.." is not a combine!!!")
end
end)
Is a normal script placed inside the player? If so, your script will break. Only localscripts can work inside the player, and be run on the client side.
Since the server handles everything, you shouldnt fire the client via the server to let the client fire the server, I recommend using a bindableEvent and fire another serverscript from the script which checks whether the player died or not
bindableEvent.Event:Connect(function(playerWhoDied)
--handle the check here
for i, player in pairs(game.Players:GetPlayers()) do
if player.TeamColor == playerWhoDied.TeamColor then
--continue..
end
end
end)