So I'm trying to make a script that when you click on this "crystal" It creates a SurfaceGui Above it. Im doing so by creating a part and placing it on the position of the crystal and then putting the surfacegui on that part, but It Isn't working; I get no errors. It's probably worng since It's my first time using SurfaceGui. Please help, Thanks!
local player = game.Players.LocalPlayer local mouse = player:GetMouse() local crystal = script.Parent mouse.ClickDetector.OnClicked:connect(function() local Part = Instance.new('Part',(game.Workspace)) Part.Position = Vector3.new(crystal.Position) Part.Size = Vector3.new(4, 1, 2) Part.Anchored = true Part.Transparency = 1 local SGui = Instance.new("ScreenGui", (Part)) local Frame = Instance.new("Frame",(SGui)) local TextLabel = Instance.new("TextLabel"),(Frame) TextLabel.Transparency = 1 TextLabel.Text = ("Work In Progress") end)
This is in a local script.
Local script's only work in a player gui or player backpack. There are also several other problems in that code:
Line 6: ClickDetector is not in the player's mouse.
line 6: OnClick is not a member of a ClickDetector.
Line 8: The extra Vector3 is not needed. Position returns the Vector3.
Line 14: Should be ("TextLabel",Frame)
You also need to assign the "Adornee" property of SurfaceGui to an object.
I know what you're trying to do, so try studying this:
-- Server script local crystal = script.Parent -- Make sure the Click Detector object is named "ClickDetector" -- Or just change the string below to it's name. local click = crystal:WaitForChild("ClickDetector") click.MouseClick:connect(function() local p = Instance.new("Part",workspace) p.Position = crystal.Position p.Anchored = true p.Transparency = 1 local s = Instance.new("SurfaceGui",p) s.Adornee = p local f = Instance.new("Frame", s) f.Size = UDim2.new(1,0,1,0) -- Frame size (max) local t = Instance.new("TextLabel",f) t.Size = UDim2.new(1,0,1,0) -- TextLabel size (max) t.BackgroundTransparency = 1 t.TextScaled = true t.Text = "hello" end)