How to make a server message when a player completes a difficulty?

Hi, I’m making a difficulty chart Obby. I want to make a server message like [User] has completed [Difficulty] whenever they complete a difficulty.
I already have something scripted, however it doesn’t work.

Current code:

local ChatService = require(game:GetService("ServerScriptService"):WaitForChild("ChatServiceRunner"):WaitForChild("ChatService"))
local server = ChatService:AddSpeaker("Server")
server:JoinChannel("All")
server:SetExtraData("NameColor", Color3.fromRGB(0, 255, 0))
server:SetExtraData("ChatColor", Color3.fromRGB(0, 255, 0))


script.Parent.Touched:Connect(function(hit)
	local char = game.Players:GetPlayerFromCharacter(hit.Parent)
	if char then
		local name = char.Name
		if game.Players[name].leaderstats.Stage.Value == 10 then
			server:SayMessage(char.Name.." has completed Effortless!", "All")
		end
	end


end)

The problem with that, is that when they touch the next checkpoint they are already at stage 11. I only want it to chat it once they complete it, not every time they join and touch it.
Thanks!

1 Like

Instead of doing all that, you can just do something like this:

StarterGui:SetCore("ChatMakeSystemMessage",{
		Text = "Text";
        Color = Color3.fromRGB(14,14,14)
	})

An example how would it look like:
image

3 Likes

I only want it to execute once, when the user completes the difficulty.

1 Like

You could always just store a value in the character or player about what stage they are on. And just use that for an if statement.

1 Like

It’ll do the same thing anyway. You could just check the leaderstats.
Checking If they are on 10 doesn’t work, because the stage changes before the if executes.
There has to be some sort of workaround without complexity (eg. storing values)

then have the if statement run first?

in the checkpoint
It’s a localscript

The trigger should be whatever moves them to the next level.

Otherwise, store an independent integer value that indicates what level was announced.

--sudo code

if currentLevel > independentLevel then
    -- anounce message here
    -- set them to be equal
    independentLevel = currentLevel
end

2 Likes

Just changed it a bit (using Shnerpy’s Obby kit by the way) and put it in the stage changer.
Thanks!