~~~~~~~~~~~~~~~~~
local msgText = "You need a key to continue."
script.Parent.Touched:connect(function(hit)
local findhum = hit.Parent:FindFirstChild("Humanoid")
if findhum then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
local findm = player.PlayerGui:findFirstChild("msg")
if not findm then
local msg = Instance.new("Message", player.PlayerGui)
msg.Text = msgText
msg.Name = "msg"
wait(5)
msg:remove()
end
end
end)
~~~~~~~~~~~~~~~~~
COMMUNITY QUESTION
How do you make it so when you touch an item, it displays a message?
2 answers
It works, the message will display. You just forgot the part at the bottom. This might fix it!
local msgText = "You need a key to continue."
script.Parent.Touched:connect(function(hit)
local findhum = hit.Parent:FindFirstChild("Humanoid")
if findhum then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
local findm = player.PlayerGui:findFirstChild("msg")
if not findm then
local msg = Instance.new("Message", player.PlayerGui)
msg.Text = msgText
msg.Name = "msg"
wait(5)
msg:remove()
end
end
end
script.Parent.Touched:connect(onTouch)
Let me know if it doesn't work.
Your problem is most likely this
player.PlayerGui:findFirstChild("msg")
Find must be capitalized for this to work. If it doesn't then post the error you are getting in the output.
1 comment
0
Still doesn't work.
This discussion is preserved as it was. New answers, comments, and votes are closed.

2 comments
how would that work if there is no function called onTouch
It still doesn't work. Maybe it's because the script doesn't state the item you touch?