Passcode machine don't work

i got a machine that asks for you to input a code into a TextBox. when you type into the textbox as a player, the text will be there on the client side, and not the server side. that is why i have cooked up a series of scripts, remote events, and a single string value object for this single darn passcode machine.

there is a button to confirm your code, and a screen display.

this first script is stored all in the button. it is the main script.

local me = script.Parent
local cd = me.ClickDetector
local sound = me["Switches Clicks Buttons Various Versions 7 (SFX)"]
local screen = me.Parent.screen
local debounce = false
local event = game.ReplicatedStorage["code machine"]
local serve = game.ReplicatedStorage["code mach server"]
local val = me.Value
cd.MouseClick:Connect(function(plr)
 if debounce == false then
  debounce = true
  sound:Play()
  event:FireAllClients()
  task.wait()
  if val.Value == "4" then
   cd:Destroy()
   screen.SurfaceGui.TextLabel.Text = "Correct. Here is your key, Xorx."
   me["Synth Sparkle Tone High Pitch Bell Tone Burs (SFX)"]:Play()
  else
   screen.SurfaceGui.TextLabel.Text = "Count again."
  end
  task.wait(2)
  screen.SurfaceGui.TextLabel.Text = "How many shelves are there in helf Life?"`
  debounce = false
 end
end)

this next script is the localscript that gets the value of the textbox on the client side:

local me = script.Parent
local event = game.ReplicatedStorage["code machine"]
local serve = game.ReplicatedStorage["code mach server"]
local box = me.Parent.screen.SurfaceGui.TextBox
local val = me.Value
print("the localscript exists")
event.OnClientEvent:Connect(function()
 serve:FireServer(box.Text)
 print(box.Text)
end)

the next script is another server script that recieves the value sent back by the localscript, and finally sets a string value’s value to the code typed out by the player:

local me = script.Parent
local event = game.ReplicatedStorage["code mach server"]
local val = me.Value

event.OnServerEvent:Connect(function(plr, code)
 val.Value = code
 print(code)
 print(val.Value)
end)

after all of that, the main server script uses the stringvalue’s value and checks if it matches the correct answer. however, it doesn’t do any of that at all. when i check the console, completely nothing is printed by the scripts, probably saying that the events have not been fired at all. or maybe it’s smth else.

also, i decided to print smth right as the localscript starts running, and the print doesn’t print at all, also probably saying that the localscript does not exist.

1 Like

Try using RemoteFunctions- theyre better for these kinda things.

Example:
insert a remotefunction into the textbox (or somewhere else idk);
then put a localscript into that remotefunc.
then type this:

local remote = script.Parent;
local textbox = script.Parent.Parent; 
remote.OnClientInvoke = function()
   return textbox.Text
end;

You can then fire this on the server:

local text = RemoteFunction:InvokeClient(player)

This should work better than firing between RemoteEvents.
If this didn’t solve your issue, please reply and ill be happy to help

1 Like

Try this:

local parent = script.Parent

local clickDetector = me.ClickDetector

local sound = parent["Switches Clicks Buttons Various Versions 7 (SFX)"]
local screen = parent.Parent.Screen

local debounce = false

local event = game.ReplicatedStorage["code machine"]

clickDetector.MouseClick:Connect(function(Player)
	if debounce then return end
	debounce = true
	
	sound:Play()
	
	local Value = tonumber(event:InvokeClient(Player))
	
	if Value ~= 4 then
		screen.SurfaceGui.TextLabel.Text = "Count again."
		return
	end
	
	clickDetector:Destroy()
	screen.SurfaceGui.TextLabel.Text = "Correct. Here is your key, Xorx."
	parent["Synth Sparkle Tone High Pitch Bell Tone Burs (SFX)"]:Play()
	task.wait(2)
	screen.SurfaceGui.TextLabel.Text = "How many shelves are there in helf Life?"
	debounce = false
end)
local parent = script.Parent

local event = game.ReplicatedStorage["code machine"]
local box = parent.Parent.screen.SurfaceGui.TextBox
local value = parent.Value

event.OnClientInvoke = function()
	return box.Text
end

i try my best to use your scripts for the localscript but somehow, the localscript still seems like it doesn’t exist ;-;. like, i try to print from the localscript but nothing comes out. even at the start. i don undertand :[

it’s not disabled or being deleted or disabled by another script. printing just doesn’t work in it.