So I’d like to make the script below into a server sided script. I want the script to broadcast a message in chat to the entire server when somebody reaches stage 31. I do not know how to make the script broadcast a message because you cannot do StarterGui:SetCore() in a server script. I’m pretty sure you need a remote event but Im not really good at scripting so I don’t know how to make that work.
Heres the local script:
function chat()
game.StarterGui:SetCore(“ChatMakeSystemMessage”,{Text = game.Players.LocalPlayer.Name..” has beaten Easy!”, Color = Color3.fromRGB(0, 255, 0), Font = Enum.Font.FredokaOne})
end
game.Players.LocalPlayer:WaitForChild(“leaderstats”).Stage.Changed:Connect(function(value)
if value == 31 then
chat()
end
end)
Again I want this to be a message that shows to the entire server, not just the player who activated the script.
function chat(Msg, Color)
game.StarterGui:SetCore("ChatMakeSystemMessage",{Text = game.Players.LocalPlayer.Name..Msg, Color = Color, Font = Enum.Font.FredokaOne})
end
game.ReplicatedStorage.SendChat:Connect(chat)
In the server script fire the remote event (FireAllClients) when needed
function chat(PlayerName)
game.StarterGui:SetCore("ChatMakeSystemMessage",{Text = PlayerName.." has beaten Easy!", Color = Color3.fromRGB(0, 255, 0), Font = Enum.Font.FredokaOne})
end
game.Players.PlayerAdded:Connect(function(Player)
local stats = Player:WaitForChild("leaderstats")
local stage = stats:WaitForChild("stage")
stage.Changed:Connect(function(NewValue)
if NewValue == 31 then
chat(Player.Name)
end
end)
end)
i forgot that .StarterGui:SetCore can be only fired on clients,
heres the fixed version
Server Script
game.Players.PlayerAdded:Connect(function(Player)
local stats = Player:WaitForChild("leaderstats")
local stage = stats:WaitForChild("stage")
stage.Changed:Connect(function(NewValue)
if NewValue == 31 then
game.ReplicatedStorage.SendMessage:FireAllClients(Player.Name)
end
end)
end)
LocalScript
game.ReplicatedStorage.SendMessage.OnClientEvent:Connect(function(PlayerName)
game.StarterGui:SetCore("ChatMakeSystemMessage",{Text = PlayerName.." has beaten Easy!", Color = Color3.fromRGB(0, 255, 0), Font = Enum.Font.FredokaOne})
end)
also create a RemoteEvent in ReplicatedStorage named SendMessage