I don't know why my script doesn't work

Hi i’m making this post because I made a script that, when someone types a secret code, it prints either CORRECT or INCORRECT. But since i’m a beginner, it wasn’t working for some reason and there’s notihng on the output page :sweat_smile::joy:

Scripts:

local CodeValue = script.Parent.Parent.Parent.Parent.Parent.PC.Screen.Code


script.Parent.Prompt.Triggered:Connect(function(player)
	game.ReplicatedStorage.EnableKGUI:FireClient(player)
	local GUI = player.PlayerGui.KeycodeGUI
	if GUI.Done.Value == true then
		print("User has given a code")
		if GUI.Frame.Frame.CodeSee.Text == CodeValue.Value then
			print("CORRECT")
		else
			print("INCORRECT")
		end
	end
end)

image script path

local KGUI = game.Players.LocalPlayer.PlayerGui.KeycodeGUI
local Chiffre = KGUI.Frame.Frame.CodeSee
local frame = script.Parent.Frame.Frame.Frame

game.ReplicatedStorage.EnableKGUI.OnClientEvent:Connect(function()
	KGUI.Enabled = true
	KGUI.Frame:TweenPosition(UDim2.new(0,0,0,0),"Out","Back",1,false)
end)

KGUI.Frame.X.MouseButton1Click:Connect(function()
    KGUI.Enabled = false
end)

for i ,key in pairs(frame:GetChildren()) do
	if string.find(key.Name, "Key") then
		key.MouseButton1Click:Connect(function()
			Chiffre.Text ..= string.match(key.Name, "%d")
		end)
	elseif key.Name == "Back" then
		key.MouseButton1Click:Connect(function()
			Chiffre.Text = string.sub(Chiffre.Text,1,0)
		end)
	elseif key.Name == "Enter" then
	    key.MouseButton1Click:Connect(function()
			script.Parent.Done.Value = true
		end)
	end
end

image localscript path

Note: Everything works except when the server tries to know if the value is true

I’m thinking maybe one of the 2 scripts can’t access the value but then it would probably error though …

remote event path : image

i’m going to sleep sorry i’ll check on this post tomorrow

1 Like

WHAT IS THIS?
shouldn’t it have .Text or .Value

oh oops maybe it’s that :sweat_smile: it’s a textlabel to i’m goin to try to add .Text

Update: it’ wasn’t that rip

i checked using print() and i saw that the script stops working here : image
at the white line

when i enter a code it does make the value to true though

1 Like

this should do:

--script
local CodeValue = script.Parent.Parent.Parent.Parent.Parent.PC.Screen.Code


game.ReplicatedStorage.EnableKGUI.OnServerEvent:Connect(function(player)
	local GUI = player.PlayerGui.KeycodeGUI
	if GUI.Done.Value == true then
		print("User has given a code")
		if GUI.Frame.Frame.CodeSee.Text == CodeValue.Value then
			print("CORRECT")
		else
			print("INCORRECT")
		end
	end
  end)
  
script.Parent.Prompt.Triggered:Connect(function(player)
	game.ReplicatedStorage.EnableKGUI:FireClient(player)
end)

--local

local KGUI = game.Players.LocalPlayer.PlayerGui.KeycodeGUI
local Chiffre = KGUI.Frame.Frame.CodeSee
local frame = script.Parent.Frame.Frame.Frame

game.ReplicatedStorage.EnableKGUI.OnClientEvent:Connect(function()
	KGUI.Enabled = true
	KGUI.Frame:TweenPosition(UDim2.new(0,0,0,0),"Out","Back",1,false)
end)

KGUI.Frame.X.MouseButton1Click:Connect(function()
    KGUI.Enabled = false
end)

for i ,key in pairs(frame:GetChildren()) do
	if string.find(key.Name, "Key") then
		key.MouseButton1Click:Connect(function()
			Chiffre.Text ..= string.match(key.Name, "%d")
      game.ReplicatedStorage.EnableKGUI:FireServer()
		end)
	elseif key.Name == "Back" then
		key.MouseButton1Click:Connect(function()
			Chiffre.Text = string.sub(Chiffre.Text,1,0)
      game.ReplicatedStorage.EnableKGUI:FireServer()
		end)
	elseif key.Name == "Enter" then
	    key.MouseButton1Click:Connect(function()
			script.Parent.Done.Value = true
      game.ReplicatedStorage.EnableKGUI:FireServer()
		end)
	end
end

Instead of using a remoteevent and setting a bool val to true use a RemoteFunction as it returns info that is returned when calling the :InvokeServer or :InvokeClient! :smiley:

2 Likes

you have replied to the wrong person

1 Like

still doesn’t work :sweat_smile:
maybe I have to use a remotefunction

did you replace both local and server script?

yes I did I can see that you changed some functions place and added some fireserver()

ok ill reply if i find something useful :yawning_face:

--script
local CodeValue = script.Parent.Parent.Parent.Parent.Parent.PC.Screen.Code


game.ReplicatedStorage.EnableKGUI.OnServerEvent:Connect(function(player)
	local GUI = player.PlayerGui.KeycodeGUI
	if GUI.Done.Value == true then
		print("User has given a code")
		if GUI.Frame.Frame.CodeSee.Text == CodeValue.Value then
			print("CORRECT")
		else
			print("INCORRECT")
		end
	end
  end)
  
script.Parent.Prompt.Triggered:Connect(function(player)
	game.ReplicatedStorage.EnableKGUI:FireClient(player)
end)
--local

local KGUI = game.Players.LocalPlayer.PlayerGui.KeycodeGUI
local Chiffre = KGUI.Frame.Frame.CodeSee
local frame = script.Parent.Frame.Frame.Frame

game.ReplicatedStorage.EnableKGUI.OnClientEvent:Connect(function()
	KGUI.Enabled = true
	KGUI.Frame:TweenPosition(UDim2.new(0,0,0,0),"Out","Back",1,false)
end)

KGUI.Frame.X.MouseButton1Click:Connect(function()
    KGUI.Enabled = false
end)

local function pressedButton(x)
  local s= string.sub(x,4,4)
  if Chiffre.Text~=""then
    Chiffre.Text=Chiffre.Text..s
  else
    Chiffre.Text=s
  end
end

for i,v in pairs(frame:GetChildren()) do
  v.MouseButton1Click:Connect(function()
    local len=#Chiffre.Text
    if v.Name=="Enter"then
			script.Parent.Done.Value = true
      game.ReplicatedStorage.EnableKGUI:FireServer()
   elseif v.Name=="Back"then
      if len>1 then
      local s=string.sub(Chiffre.Text,1,#Chiffre.Text-1)
      Chiffre.Text=s
      elseif len==1 then
        Chiffre.Text=""
      else
        Chiffre.Text=""
      end
      
    else
    v.MouseButton1Click:Connect(pressedButton(v.Name))
    end
  end)
end

That’s it
won’t edit anymore sorry about that

please tell me if this works
last try

1 Like

Rip still doesn’t work :sweat_smile: but thanks a lot of helping though
i’m going to rewrite the script maybe

1 Like

Ok

no errors right?

Thanks for testing

1 Like

yea there’s no errors but the script just stops itself

at this point i’ll just take a script from a free model :sweat_smile:

sorry but the problem seem to be occuring because there is no update in the server
i found something lets try 1 more time and ill give up

1 Like

Ok thank you so much for helping

--script
local CodeValue =script.Parent.Parent.Parent.Parent.Parent.PC.Screen.ChildRemoved

game.ReplicatedStorage.EnableKGUI.OnServerEvent:Connect(function(player,complete,text)
	local GUI = player.PlayerGui.KeycodeGUI
  GUI.Done.Value=complete
	if GUI.Done.Value == true then
		print("User has given a code")
		if text == CodeValue.Value then
			print("CORRECT")
		else
			print("INCORRECT")
		end
	end
  end)
  
script.Parent.Prompt.Triggered:Connect(function(player)
	game.ReplicatedStorage.EnableKGUI:FireClient(player)
end)
--local

local KGUI = game.Players.LocalPlayer.PlayerGui.KeycodeGUI
local Chiffre = KGUI.Frame.Frame.CodeSee
local frame = script.Parent.Frame.Frame.Frame

game.ReplicatedStorage.EnableKGUI.OnClientEvent:Connect(function()
	KGUI.Enabled = true
	KGUI.Frame:TweenPosition(UDim2.new(0,0,0,0),"Out","Back",1,false)
end)

KGUI.Frame.X.MouseButton1Click:Connect(function()
    KGUI.Enabled = false
end)

local function pressedButton(x)
  local s= string.sub(x,4,4)
  if Chiffre.Text~=""then
    Chiffre.Text=Chiffre.Text..s
  else
    Chiffre.Text=s
  end
end

for i,v in pairs(frame:GetChildren()) do
  v.MouseButton1Click:Connect(function()
    local len=#Chiffre.Text
    local done=script.Parent.Done
    if v.Name=="Enter"then
			done.Value = true
      game.ReplicatedStorage.EnableKGUI:FireServer(done.Value,Chiffre.Text)
   elseif v.Name=="Back"then
      if len>1 then
      local s=string.sub(Chiffre.Text,1,#Chiffre.Text-1)
      Chiffre.Text=s
      elseif len==1 then
        Chiffre.Text=""
      else
        Chiffre.Text=""
      end
      
    else
    v.MouseButton1Click:Connect(pressedButton(v.Name))
    end
  end)
end

last try thanks for not giving up :grin:

Ok I think it works now it’s just my code value now but thanks for helping !

seems you have some trouble since i modified the code:

--script
local CodeValue = script.Parent.Parent.Parent.Parent.Parent.PC.Screen.Code

game.ReplicatedStorage.EnableKGUI.OnServerEvent:Connect(function(player,complete,text)
	local GUI = player.PlayerGui.KeycodeGUI
  GUI.Done.Value=complete
	if GUI.Done.Value == true then
		print("User has given a code")
		if text == CodeValue.Value then
			print("CORRECT")
		else
			print("INCORRECT")
		end
	end
  end)

script.Parent.Prompt.Triggered:Connect(function(player)
	game.ReplicatedStorage.EnableKGUI:FireClient(player)
end)
--local
local KGUI = game.Players.LocalPlayer.PlayerGui.KeycodeGUI
local Chiffre = KGUI.Frame.Frame.CodeSee
local frame = script.Parent.Frame.Frame.Frame

game.ReplicatedStorage.EnableKGUI.OnClientEvent:Connect(function()
	KGUI.Enabled = true
	KGUI.Frame:TweenPosition(UDim2.new(0,0,0,0),"Out","Back",1,false)
end)

KGUI.Frame.X.MouseButton1Click:Connect(function()
    KGUI.Enabled = false
end)

for i ,key in pairs(frame:GetChildren()) do
	if string.find(key.Name, "Key") then
		key.MouseButton1Click:Connect(function()
			Chiffre.Text ..= string.match(key.Name, "%d")
		end)
	elseif key.Name == "Back" then
		key.MouseButton1Click:Connect(function()
			Chiffre.Text = string.sub(Chiffre.Text,1,0)
		end)
	elseif key.Name == "Enter" then
	    key.MouseButton1Click:Connect(function()
			script.Parent.Done.Value = true
        game.ReplicatedStorage.EnableKGUI:FireServer(script.Parent.Done.Value,Chiffre.Text)
		end)
	end
end

this version i just added the server event and passed arguments into the fire server everything else untouched

2 Likes