Help in Touch event

I’m trying to when a player touch a part, one Frame will show, but I can’t make it works, here’s my script

script.Parent.Touched:Connect(function(hit)
    local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
    if player then
        player.PlayerGui.Gui.Frame.Visible = true
	end
end)

Thanks for help.

1 Like

Is this a server script? If so, change it to this:

script.Parent.Touched:Connect(function(hit)
    local player
    if hit.Parent:IsA("Model") then
        player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
    elseif hit.Parent.Parent:IsA("Model") then
        player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent.Parent)
    end

    if player then
        player.PlayerGui.ScreenGui.Frame.Visible = true
	end
end)

You haven’t written the correct path, it should go Player > PlayerGui > Gui > GuiElement
you just went from PlayerGui straight to GuiElement

It’s wrong sorry, because I edited this, but in my original it’s right

Its a local script and not a server script

Send the original so we can help you

LocalScripts cannot run with a Part parent.

2 Likes
script.Parent.Touched:Connect(function(hit)
    local player = game.Players:FindFirstChild(hit.Parent.Name) -- either hit.Parent or hit.Parent.Name not sure
    if player then
        player.PlayerGui.Gui.Frame.Visible = true
	end
end)

Edit: since it is a local script this wouldnt work, you would have to do some work with remote events.

Can You Send Us The Full Script? It Would help much more!

also what is all of the names of the parts and UI your trying to change?

I only change to normal script and worked.