This is my code:

local Gate = script.Parent.Gate
local GateOrgcf = Gate.PrimaryPart.CFrame
local CurrentCFrameTweenValue = script.CurrentCFrameTween; CurrentCFrameTweenValue.Value = GateOrgcf -- hack?
local TweenService = game:GetService('TweenService')
local Toggle = script.Parent.Toggle
local Light = Toggle.Light
local Tween = game:GetService('TweenService')
local Open = false
local Toggling = false

local RenderRemote = game.ReplicatedStorage.GateRenderToggle

local lightColors = {
	togglelights = BrickColor.Red();
	readylights = BrickColor.Green()
}

local function toggleLights(color)
	if color then
		Toggle.BrickColor = color
		Light.Color = Toggle.BrickColor.Color
	end
end

local function openGate()
	if Toggling then return end
	toggleLights(lightColors.togglelights)
	Toggling = true
	local goal = {}
	goal.Value = (GateOrgcf * CFrame.new(27, 0, 0))
	RenderRemote:FireAllClients(CurrentCFrameTweenValue, Toggling, Gate, goal)
	local ServerTween = TweenService:Create(CurrentCFrameTweenValue, TweenInfo.new(6), goal)
	ServerTween:Play()
	-- tween logic
	ServerTween.Completed:Wait()
	toggleLights(lightColors.readylights)
	script.Parent.Alert.Buzzer:Stop()
	Toggling = false
	Open = true
end

local function closeGate()
	if Toggling then return end
	toggleLights(lightColors.togglelights)
	Toggling = true
	local goal = {}
	goal.Value = GateOrgcf
	RenderRemote:FireAllClients(CurrentCFrameTweenValue, Toggling, Gate, goal)
	local ServerTween = TweenService:Create(CurrentCFrameTweenValue, TweenInfo.new(6), goal)
	ServerTween:Play()
	-- tween logic
	ServerTween.Completed:Wait()
	toggleLights(lightColors.readylights)
	script.Parent.Alert.Buzzer:Stop()
	Toggling = false
	Open = false
end

Toggle.Detector.MouseClick:Connect(function(player)
	if not checkForGroup(player) or Toggling then return end
	script.Parent.Alert.Buzzer:Play()
	script.Parent.Gate.Gate.Opening:Play()
	if not Open then
		openGate()
	else
		closeGate()
	end
end)

and I don't know what is wrong. Everything should work with it, but it doesn't. any ideas to help?

1 comment

0

(PS) the local Gate = script.Parent.Gate, that gate is a model, not a single part!