So I have this “computer” (really just a block with a SurfaceGui) and the point of my script is that if the correct code is entered, the monitor will become slightly transparent. The issue is when I try to enter the code to make the monitor transparent in Play Solo mode, clicking the numbers on the numpad does…nothing. But, when I do it in Run mode, it works perfectly fine.
The following script is from a free model code door that I edited to be used on a ScreenGui.
Are all of your number buttons (N1, N2, N3, etc) TextButtons? If so, I recommend using MouseButton1Click rather than Activated. I’m not sure if this will fix your problem though.
^ just kidding on that part, Activated is better.
Also, is this running in a LocalScript or a server Script?
Welp, I changed it to MouseButton1Click while you were editing, and it works. I’m not sure how Activated is better, feel free to explain. if you’d like
P.S. All of the buttons are TextButtons and it is in a server Script.
Activated is meant to work cross-platform, while MouseButton1Click(I assume) only works with a mouse&keyboard setup (which is 99% of the time only PC).
I’m not sure why the latter works in this case but the former doesn’t, because as far as I knew, SurfaceGui button presses were replicated to the server. Just in case they aren’t though, it may be worthwhile to put it in a LocalScript instead and have a second server Script in ServerScriptService to catch events. Maybe this way you’d still be able to use Activated?
local TheCode = "4958"
local Input = ""
local Btns = game.Workspace.Monitor.SurfaceGui.Frame
Btns.Clear.Activated:Connect(function()
Input = ""
print("Code Cleared")
end)
--ENTER FUNCTION
Btns.Enter.Activated:Connect(function()
if Input == TheCode then
workspace.Monitor.Transparency = .7
else
Input == ""
print("Incorrect Code")
end
end)
for i,v in pairs(Btns:GetChildren()) do
if string.sub(v.Name, 1, 1) == "N" then
v.Activated:Connect(function()
local Add = string.sub(v.Name, 2, #v.Name)
Input = Input..Add
end)
end
end
When scripting, Instead of writing things out manually, You can make an automatic system.
Also also, I’d like to mention, you used return and honestly that wasn’t necessary, You can just use else as I did above.
Yeah, then your best bet would definitely be a LocalScript that catches the .Activated events and transmits the necessary information via RemoteEvents to a separate script somewhere else (ServerScriptService would be best imo).
Let me know if this works, as I haven’t done any testing.
I’ve used MouseButton1Click before, and it appears to work perfectly cross platform others say. It could just be a problem within your code. Perhaps it stops functioning somewhere.