Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do you make it so when you touch an item, it displays a message?

Asked by 7 years ago
Edited 7 years ago

````I've tried my old scripting but it doesn't work, I think they updated the coding in Roblox.~~~~~~~~~~~~~~~~~

01local msgText = "You need a key to continue."
02 
03script.Parent.Touched:connect(function(hit)
04    local findhum = hit.Parent:FindFirstChild("Humanoid")
05    if findhum then
06        local player = game.Players:GetPlayerFromCharacter(hit.Parent)
07        local findm = player.PlayerGui:findFirstChild("msg")
08        if not findm then
09            local msg = Instance.new("Message", player.PlayerGui)
10            msg.Text = msgText
11            msg.Name = "msg"
12            wait(5)
13            msg:remove()
14        end
15    end
16end)

2 answers

Log in to vote
0
Answered by 7 years ago

It works, the message will display. You just forgot the part at the bottom. This might fix it!

01local msgText = "You need a key to continue."
02 
03script.Parent.Touched:connect(function(hit)
04    local findhum = hit.Parent:FindFirstChild("Humanoid")
05    if findhum then
06        local player = game.Players:GetPlayerFromCharacter(hit.Parent)
07        local findm = player.PlayerGui:findFirstChild("msg")
08        if not findm then
09            local msg = Instance.new("Message", player.PlayerGui)
10            msg.Text = msgText
11            msg.Name = "msg"
12            wait(5)
13            msg:remove()
14        end
15    end
16end
17 
18script.Parent.Touched:connect(onTouch)

Let me know if it doesn't work.

0
how would that work if there is no function called onTouch justoboy13 153 — 7y
0
It still doesn't work. Maybe it's because the script doesn't state the item you touch? vlogdtp 0 — 7y
Ad
Log in to vote
0
Answered by 7 years ago

Your problem is most likely this

1player.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.

0
Still doesn't work. vlogdtp 0 — 7y

Answer this question