part = script.Parent
local function chat(message)
game.StarterGui:SetCore("ChatMakeSystemMessage", {Text = message, Colour = Color3.fromRGB(255,255,255), Font = Enum.Font.ArialBold})
end
local messages = {"You got the egg of noob #1"} -- Replace Test Message with any text. To add more, put a comma after the " and put another in ""
function onTouch(part)
local humanoid = part.Parent:FindFirstChild("Humanoid")
if (humanoid ~= nil) then -- if a humanoid exists, then
chat(messages[math.random(1,#messages)])
end
end
script.Parent.Touched:connect(onTouch)
It obviously dosen’t work but i am confused as hell.
ChatMakeSystemMessage
Only works on local scripts, if you’re going to use that, you can use remote events or use a server script and implement what @d_hq said.
local sss = game.ServerScriptService
local Players = game:GetService("Players")
local chatService = require(sss:WaitForChild('ChatServiceRunner'):WaitForChild('ChatService'))
part = script.Parent
local function chat(message)
ChatService:GetChannel('All')
Channel:SendSystemMessage("{System}: "message)
end
local messages = {"You got the egg of noob #1"} -- Replace Test Message with any text. To add more, put a comma after the " and put another in ""
function onTouch(part)
local humanoid = part.Parent:FindFirstChild("Humanoid")
if (humanoid ~= nil) then -- if a humanoid exists, then
local Plr = Players:GetPlayerFromCharacter(part.Parent)
chat(Plr.Name..", got the egg of noob #1")
end
end
script.Parent.Touched:connect(onTouch)
local Players = game:GetService("Players")
script.Parent.Touched:Connect(function(Hit)
local Model = Hit:FindFirstAncestorOfClass("Model")
if not Model then return end
local Player = Players:GetPlayerFromCharacter(Model)
if not Player then return end
-- do stuff with player
end)
local sss = game.ServerScriptService
local Players = game:GetService("Players")
local chatService = require(sss:WaitForChild('ChatServiceRunner'):WaitForChild('ChatService'))
part = script.Parent
local function chat(message)
local Channel = ChatService:GetChannel('All')
Channel:SendSystemMessage("{System}: "message)
end
local messages = {"You got the egg of noob #1"} -- Replace Test Message with any text. To add more, put a comma after the " and put another in ""
function onTouch(part)
local humanoid = part.Parent:FindFirstChild("Humanoid")
if (humanoid ~= nil) then -- if a humanoid exists, then
chat(part.Parent.Name..", got the egg of noob #1")
end
end
script.Parent.Touched:connect(onTouch)
I jut realized a mistake I made, sorry. This script should work, it gets the player’s name from the character and says the player’s name in the chat and that they got the egg.
in chat function when you’re doing Channel:SendSystemMessage("{System}: "message), you should be doing Channel:SendSystemMessage("{System}: "..message)
and the ontouch function should look something like this
function onTouch(part)
local humanoid = part.Parent:FindFirstChild("Humanoid")
if (humanoid ~= nil) then -- if a humanoid exists, then
chat(part.Parent.Name..", got the egg of noob #1") -- or messages[math.random(1,#messages)]
end
end