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

Is my ClickDetector script setup right?

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

4 comments

0

Are there any errors? Did you try printing within the onClicked function?

0

There are no errors when I click it, and printing wont work

0

Are there any errors prior to you clicking? One which refers to line 1, perhaps?

0

nope

3 answers

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.

3 comments

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

0

Like, change another Interface's text??

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.

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!

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

2 comments

0

That won't make it work for only one player. The script will need to be a LocalScript.

0

Oh sorry, yeah it is in a LocalScript

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