Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why Isn't this script working?

Asked by 8 years ago

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

Log in to vote
1
Answered by 8 years ago

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)
0
Still Doesn't work 64batsalex 45 — 8y
0
I updated it. CodingEvolution 490 — 8y
0
I know, It still doesn't work :( 64batsalex 45 — 8y
0
What does the output say and how are you using it. CodingEvolution 490 — 8y
View all comments (10 more)
0
Output says nothing, no errors. 64batsalex 45 — 8y
0
Oh wait, it's in a local script. That's why. CodingEvolution 490 — 8y
0
Is it not suppose to be? 64batsalex 45 — 8y
0
So what romove the player variable? 64batsalex 45 — 8y
0
No... Read my answer, i updated it. CodingEvolution 490 — 8y
0
You said the problem is , is that it's a local script right? 64batsalex 45 — 8y
0
I'll rewrite it. CodingEvolution 490 — 8y
0
Okay, Thanks. 64batsalex 45 — 8y
0
The part is inserting, but The surfacegui Isn't showing on the part 64batsalex 45 — 8y
0
Cause you didn't give the GUI a size. I'll update the answer again. CodingEvolution 490 — 8y
Ad

Answer this question