How to use clickdetector locally?

Hi, hope youre having a good day

Well, basically, im making a game with a friend, and we need to make a door that “opens” when certain word is typed.

For that i made a GUI and a textbox, however textbox text doesnt replicate to the server, so i did a localscript

But, clickdetector.MouseClick doesnt replicate to the client ._____.

So, is there a way i can make clickdetector local? or textbox server sided?

Heres my code if you need

local text = "sputnik"
local d = game.Workspace.banco1
local p = game.Players.LocalPlayer

	script.Parent.MouseClick:Connect(function()
		p.PlayerGui.keygui.Frame.Visible = true
		if p.PlayerGui.keygui.Frame.TextBox.Text == text then
			d.CanCollide = false
			d.Transparency = 0.7
			p.PlayerGui.keygui.Frame.Visible = false
			wait(10)
			d.CanCollide = true
			d.Transparency = 0
		end
end)

1 Like

You can use a remote event, and use FireClient if you want to do that

1 Like

This is false. ClickDetector.MouseClick fires off on both client and server.

EDIT: So, in order to make it local, listen for ClickDetector.MouseClick in a LocalScript and then fire a RemoteEvent.

1 Like

lol, i thought clickdetector didnt replicate to client. Becouse in server worked but client didnt

Tysm for replying, i will do that and see if works

1 Like

I think I understand what you’re trying to do here.

With the limited patch of code, I’m assuming you’re clicking on the door, and it shows a textbox that you write the password in.

What’s happening is that the moment you click the door it runs this line:
if p.PlayerGui.keygui.Frame.TextBox.Text == text then

That line is checking if what’s written inside the textbox is “sputnik” the same moment you clicked the door.

There’s a couple of ways for you to do this. Instead of instantly checking for the password (which is impossible for you to write in such a short time frame) you could add wait(3) and it’ll check for the password 3 seconds after you clicked the door, for example:

local text = “sputnik”
local d = game.Workspace.banco1
local p = game.Players.LocalPlayer

script.Parent.MouseClick:Connect(function()
	p.PlayerGui.keygui.Frame.Visible = true
            wait(3)
	if p.PlayerGui.keygui.Frame.TextBox.Text == text then
		d.CanCollide = false
		d.Transparency = 0.7
		p.PlayerGui.keygui.Frame.Visible = false
		wait(10)
		d.CanCollide = true
		d.Transparency = 0
	end

end)

OR

Instead of running all the code at the same time, you could add a button that reads what you wrote inside the textbox, for this you’d have inserted a button inside your GUI. Example code:

local text = “sputnik”
local d = game.Workspace.banco1
local p = game.Players.LocalPlayer

script.Parent.MouseClick:Connect(function()
	p.PlayerGui.keygui.Frame.Visible = true
            p.PlayerGui.keygui.Frame.TextButton.Visible = true
    end)
    p.PlayerGui.keygui.Frame.TextButton.MouseButton1Click:Connect(function())
        if p.PlayerGui.keygui.Frame.TextBox.Text == text then
	       d.CanCollide = false
	       d.Transparency = 0.7
	       p.PlayerGui.keygui.Frame.Visible = false
                   p.PlayerGui.keygui.Frame.TextButton.Visible = false
	       wait(10)
	        d.CanCollide = true
	       d.Transparency = 0
end

end)

This kind of a long post, shoot any question.

EDIT: Forgot to mention that if you only run the code in a localscript, the “door” will only open for the player that put the password correctly and not the entire server, since localscripts don’t replicate to the server unless you use remoteFunctions.

3 Likes

thank you! with your explanation everything was much clearer for me

EDIT: it works! after cloning the code to playergui and correcting what you said, it worked! tysm

2 Likes