Hello! I am trying to make an gate open and close with a click of a GUI button. I sorta have it working, it opens but then closes immediately after.
Example of what I mean: https://gyazo.com/156f24de251a7d61db1f17252a836184
Code:
LocalScript GUI Side -
GateBtn.MouseButton1Click:Connect(function()
if GateOpen == false then
GateOpen = true
OpenLaneGate:FireServer()
GateBtn.TextButton_Roundify_12px.TextLabel.Text = "Close Gate"
GateBtn.TextButton_Roundify_12px.ImageColor3 = Color3.new(0, 1, 0)
elseif GateOpen == true then
GateOpen = false
GateBtn.TextButton_Roundify_12px.TextLabel.Text = "Open Gate"
GateBtn.TextButton_Roundify_12px.ImageColor3 = Color3.new(1, 0, 0)
CloseLaneGate:FireServer()
end
end)
Server Side -
local OpenLaneGateEvent = game.ReplicatedStorage.OpenLaneGate
local CloseLaneGateEvent = game.ReplicatedStorage.CloseLaneGate
local hingeGroup = game.Workspace:WaitForChild("BoothMainEntrance"):WaitForChild("HingeGroup1")
local primCF = hingeGroup:GetPrimaryPartCFrame()
local Cooldown = false
local function OpenGateFired()
if Cooldown == false then
Cooldown = true
for i = 0, 1, 0.05 do
hingeGroup:SetPrimaryPartCFrame(primCF:Lerp(primCF * CFrame.Angles(0, 0, math.rad(-75)), i))
wait()
end
hingeGroup:SetPrimaryPartCFrame(primCF * CFrame.Angles(0, 0, math.rad(-75)))
wait(10)
Cooldown = false
if Cooldown == true then
end
end
end
local function CloseGateFired()
for i = 1, 0, -0.05 do
hingeGroup:SetPrimaryPartCFrame(primCF:Lerp(primCF * CFrame.Angles(0, 0, math.rad(-75)), i))
wait()
end
hingeGroup:SetPrimaryPartCFrame(primCF)
end
OpenLaneGateEvent.OnServerEvent:Connect(CloseGateFired)
OpenLaneGateEvent.OnServerEvent:Connect(OpenGateFired)
What am I doing wrong, and what do I need to do to accomplish my task?