-
**What do you want to achieve? When a player presses the C key or a GUI button, I would like a sound to play and UI to warn their team of danger.
-
**What is the issue? When I run the script on the server-side, it replicates for each player in the server, so if there were three players, it would repeat 3 times for each player instead of only once per player. When I run it on the client-side, it only appears once, but only on the player who fired it.
-
**What solutions have you tried so far? running print statements and trying to run it on the client with a local script.
Here is the local script:
local Players = game:GetService("Players")
local player = game.Players.LocalPlayer
local UserInputService = game:GetService("UserInputService")
local db = false
local frame = script.Parent
local danger = frame.Danger
local help = frame.Help
local attack = frame.Attack
local taunt = frame.Taunt
local debris = game:GetService("Debris")
local rs = game:GetService("ReplicatedStorage")
local function danger(inputObject, gameProcessedEvent)
if gameProcessedEvent then
return
end
if inputObject.KeyCode == Enum.KeyCode.C and db == false then
game.ReplicatedStorage.RemoteEvents.Danger:FireServer()
db = true
wait(5)
db = false
end
end
UserInputService.InputBegan:Connect(danger)
danger.MouseButton1Click:Connect(function()
if db == false then
game.ReplicatedStorage.RemoteEvents.Danger:FireServer()
db = true
wait(5)
db = false
end
end)
Here is the server script:
local player = script.Parent.Parent.Parent.Parent
local stats = player:WaitForChild("leaderstats")
local Players = game:GetService("Players")
local rs = game:GetService("ReplicatedStorage")
local debris = game:GetService("Debris")
game.ReplicatedStorage.RemoteEvents.Danger.OnServerEvent:Connect(function(player)
player.Character.Head.Danger:Play()
for i, v in pairs(Players:GetPlayers()) do
if v.Team.TeamColor == player.Team.TeamColor then
local comms = rs.UI.Comms:Clone()
comms.Title.Text = player.Name
if v.Team.TeamColor == game.Teams.Red.TeamColor then
comms.Title.TextColor3 = Color3.new(1,0,0)
elseif v.Team.TeamColor == game.Teams.Blue.TeamColor then
comms.Title.TextColor3 = Color3.new(0,0,1)
elseif v.Team.TeamColor == game.Teams.Green.TeamColor then
comms.Title.TextColor3 = Color3.new(0,1,0)
end
comms.Action.TextColor3 = Color3.new(1,1,0)
comms.Action.Text = " wants to retreat!"
comms.Parent = v.PlayerGui.Comms.Comms
debris:AddItem(comms,3)
end
end
end)