I have been trying to make a ScreenGui appear when a Part is touched, however it does not seem to appear, and I think there may be an error in the code I am using. I appreciate anyone who can help me resolve this. Thanks.
local Model = game.Workspace.Part
function destroy()
game.Workspace.Part:Destroy()
end
script.Parent.Touched:connect(destroy)
function move()
local touched
Model.Touched:connect(function(hit)
if hit and hit.Parent:FindFirstChild("Humanoid") then
touched = true
end
end)
while not touched do
Model.Position =
Vector3.new(math.random(),math.random(),math.random())*10
wait(0.5)
end
end
game.Players.PlayerAdded:connect(move)
function screen(Part)
local Gui = game:GetService("ServerStorage").ScreenGui
local Player = game.Players:GetPlayerFromCharacter(Part.Parent)
if Player and not Player.PlayerGui:FindFirstChild(Gui.Name) then
Gui:Clone().Parent = Player.PlayerGui
end
end
script.Parent.Touched:connect(screen)

8 comments
Is this all of the code?
For the ScreenGui, yes. I have 2 other functions in the script but they're for different things.
what is the entire move function? Something seems to be missing (e.g. I don't know what "Part" is. There is a closing parenthesis at line 7 that shouldn't be there. Why is the Touch event connected to move instead of screen, etc.)
I apologize, let me edit that for you. I simply forgot to add screen instead of move, as my previous function was about moving the Part.
And when I remove the closing command at line 7, line 8 becomes incorrect.
Is this in a localscript?
No, a normal script. I was unsure as I had two other functions.
Any chance that the part is getting destroyed before the rest of the script can run?