I’m trying to make a combination code system with random values, but sometimes the code is instantly correct and the door opens immediately, which i don’t want to happen.
Script:
local gate = script.Parent.Gate
local code = nil
repeat until code ~= 0000 do
code = (math.random(0,1)..math.random(0,1)..math.random(0,1)..math.random(0,1))
end
local ts = game:GetService("TweenService")
local gateinfo = TweenInfo.new(2.12,Enum.EasingStyle.Sine)
local gatepos = gate.Position
print(code)
local valve1 = script.Parent.Valve1
local valve2 = script.Parent.Valve2
local valve3 = script.Parent.Valve3
local valve4 = script.Parent.Valve4
local solved = false
while wait(0.1) do
if solved == false then
local plrcode = valve1.Value.Value..valve2.Value.Value..valve3.Value.Value..valve4.Value.Value
print(plrcode)
if plrcode == code then
solved = true
valve1.Valve.Attachment.ProximityPrompt.Enabled = false
valve2.Valve.Attachment.ProximityPrompt.Enabled = false
valve3.Valve.Attachment.ProximityPrompt.Enabled = false
valve4.Valve.Attachment.ProximityPrompt.Enabled = false
script.Parent.Light.Color = Color3.fromRGB(0, 255, 0)
script.Parent.Light.PointLight.Color = Color3.fromRGB(0, 255, 0)
script.Parent.Sircom.Sound:Play()
script.Parent.Sircom.Sound.Ended:Wait()
wait(0.5)
local tween = ts:Create(gate,gateinfo,{Position = Vector3.new(gatepos.X,gatepos.Y+8,gatepos.Z)})
tween:Play()
gate.Sound:Play()
end
end
end
You should maybe set this variable after you have completed the door logic and the tween playing on it.
Your wait signal on the whole function is less than the time required to solve and animate the door. Yet you set the ‘solved’ variable as true straight away and expect the function not to re-enter.
That seemed to work I’m running and stopping the game over and over again, and i have not seen the code been 0000 yet! I’ll mark it as a solution after some more testing.
No that wouldn’t be smart. Because then the door opening function is gonna keep repeating over and over again when the code is solved. Until one iteration of the door opening is done.
Yeah I can see the logic, it is not the way I would do it. This function will run FOREVER, whether the door is open or not, unless you destroy the script manually. There are better methods than an endless while loop.