How to make a message when the player touch the part?

Hi guys,

I wanted to make a part that when a player touched it will send a message on the chat with player name in it like “Username has completed!”

I tried a lot of things but it doesn’t work. I have been searching for over 1 year of this but I did not find the perfect one. I searched Google, YouTube, and more but still.

I’m new to Roblox scripting so if you know how to make a script that can do that, please let me know and I’ll very much appreciate it.

6 Likes
  • We can’t make whole scripts until you have a error or other conditions

  • You should use Touched Event a Chat Message Scripts there are many of them and lots of tutorial on YouTube also about how to do it

  • Here is a basic script:
    LOCAL FOR EXPLAINATION

local Part = yourPartHere --for eg game.Workspace.Part

Part.Touched:Connect(function (Hit) --Hit is the object that touches it
if Hit.Parent:FindFirstChild("Humanoid") then --Checking if it's a player or not
--Chat send code here
end
end)
1 Like
local ChatService = require(game:GetService("ServerScriptService"):WaitForChild("ChatServiceRunner"):WaitForChild("ChatService"))
local server = ChatService:AddSpeaker("Server")
server:JoinChannel("All")
server:SetExtraData("NameColor", Color3.fromRGB(255, 255, 255))
server:SetExtraData("ChatColor", Color3.fromRGB(0, 255, 255))


script.Parent.Touched:Connect(function(hit)
    local char = hit:FindFirstAncestorOfClass("Model")

    server:SayMessage(char.Name.." has completed!", "All")
end)
10 Likes

And just for clarification, what game is this?

Is this an obby game? If so, do you have a leaderstat for stage? More information would be useful

1 Like

It is an obby game. I do not have leaderstats for stage because its a tower like Tower of Hell.

1 Like

Oh, ok. Is there any form of checkpoints?

1 Like

Nope. But I have a game before but its discontinued because of the checkpoints lol.

1 Like

And one final question, does this message only appear when you beat the obby?

1 Like

Yes.

((((((30 characters))))))

1 Like

Ok, so something I’d recommend:

For all of the players, they should have a BoolValue already in their character named “BeatObby”. You can put this BoolValue under StarterCharacterScripts (it’ll be inside the character model). It’ll already be set to false, which is what you want (this will prevent the chat spamming that the player has beat the obby).

Now, for the message script, I would change it to this:

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


script.Parent.Touched:Connect(function(hit)
    local char = hit:FindFirstAncestorOfClass("Model")

    if char:FindFirstChild("BeatObby").Value == false then
        char.BeatObby.Value = true
        server:SayMessage(char.Name.." has completed the obby!", "All")
    end
end)

And then at the beginning of every round, you can loop through all the players and set the BoolValue back to false like this:

for _, v in pairs(game.Players:GetPlayers()) do
    v.Character:WaitForChild("BeatObby").Value = false
end

Hope this helps, and good luck.

6 Likes

Thanks and stay safe!

((30 characters))

2 Likes

And btw do you know how to make a Progress bar like Tower of Hell?

Will be appreciated if you know how to!

1 Like

Not at this moment lol, but If I find out, I’ll tell you a method

1 Like

Thanks man! Do you have Discord? I can talk with you about scripts without posting it into DevForum, it would be easier.

My tag: OfficialRolly#8468

Thanks!

1 Like

Ologist#6064

(((((30 chars)))))

Added you on Discord. The last account I gave you is deleted after 14 days.

Hi there, sorry for the post bump!

I am using this script, so helpful so thank you @OIogist for making it! I’m not using the BoolValue script but just the normal one.

When the player touches it then it spams the message in the chat until they get off the block. Anyway to fix this, if not I’ll just create a script that teleports them away from the block?

how would i make this work for multiple parts? it only works for 1 part.