Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why Isn't this script working?

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.

1 answer

✓ Accepted answer

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)

14 comments

0

Still Doesn't work

0

I updated it.

0

I know, It still doesn't work :(

0

What does the output say and how are you using it.

0

Output says nothing, no errors.

0

Oh wait, it's in a local script. That's why.

0

Is it not suppose to be?

0

So what romove the player variable?

0

No... Read my answer, i updated it.

0

You said the problem is , is that it's a local script right?

0

I'll rewrite it.

0

Okay, Thanks.

0

The part is inserting, but The surfacegui Isn't showing on the part

0

Cause you didn't give the GUI a size. I'll update the answer again.

This discussion is preserved as it was. New answers, comments, and votes are closed.