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)
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)
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.