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 6 years ago
Edited 6 years ago

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

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)

2 answers

Log in to vote
0
Answered by 6 years ago

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.

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

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.

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

Answer this question