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

Is my ClickDetector script setup right?

Asked by
NRCme 0
7 years ago
Edited 7 years ago

In my test/modeling workspace I have a table that when you click it, it should change the text of a screen

And, it doesn't work..

Code:

local infoScreenTable = game.Workspace.InfoScreen.SurfaceGui.Table

function onClicked()
    infoScreenTable.Text = "Big Table"
end

script.Parent.ClickDetector.MouseClick:connect(onClicked)

It is in a local script

I have concluded that you can't use a click detector in a localscript

0
Are there any errors? Did you try printing within the onClicked function? Pyrondon 2089 — 7y
0
There are no errors when I click it, and printing wont work NRCme 0 — 7y
0
Are there any errors prior to you clicking? One which refers to line 1, perhaps? Pyrondon 2089 — 7y
0
nope NRCme 0 — 7y

3 answers

Log in to vote
0
Answered by
rexbit 707 Moderation Voter
7 years ago
Edited 7 years ago

For an actual locally seen part either activate FE or Place the part into CurrentCamera.

local infoScreenTable = workspace:WaitForChild("InfoScreen").SurfaceGui.Table

script.Parent.ClickDetector.MouseClick:connect(function(player)
    infoScreenTable.Text = "Big Table"
end)

Edited

Use a Server script.

0
I don't care who sees the screen brick(I know before I said screen, but not the brick) I want to have it so that when you click it it changes the text of the screen NRCme 0 — 7y
0
Like, change another Interface's text?? rexbit 707 — 7y
0
No, what he means is: Just keep it in Workspace with a server script, and when you click it the text just changes for everyone. TheDeadlyPanther 2460 — 7y
Ad
Log in to vote
0
Answered by
Valatos 166
7 years ago
Edited 7 years ago

Try using this one :P this script is made to be a script thats inside the brick

local Detector = script.Parent -- The part where the clickdetector is inside
local infoScreenTable = workspace:WaitForChild("InfoScreen").SurfaceGui.Table -- The location of the screen

Detector.ClickDetector.MouseClick:connect(function(plr) -- Plr is the player thatclicks it
    infoScreenTable.Text = "Big Table"
end)

I hope this worked for you!

Log in to vote
-2
Answered by 7 years ago

Yes , it is but make sure that your event handler setup like this in case you want only certain players to see the text:

function onClick(player)
 infoScreenTable.Text = "Big Table"
end
0
That won't make it work for only one player. The script will need to be a LocalScript. TheDeadlyPanther 2460 — 7y
0
Oh sorry, yeah it is in a LocalScript NRCme 0 — 7y

Answer this question