Portal Gun tween not working

I’m trying to make a make a portal gun, but whenever I test it out, my camera zooms in and I can’t zoom out or move.
Here’s my Tweening script on the client-side:

local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TweenService = game:GetService("TweenService")

local Camera = workspace.CurrentCamera

local Blue = Color3.fromRGB(0, 85, 122)
local Orange = Color3.fromRGB(255, 120, 0)

local Part
local IdentifierToSend

local function tweenCamera(Time, Style, Direction, FOV)
	local info = TweenInfo.new(Time, Enum.EasingStyle[Style], Enum.EasingDirection[Direction], 0, false, 0)
	local Tween = TweenService:Create(
		Camera,
		info,
		{FieldOfView = FOV}
	)
	Tween:Play()
	Tween.Completed:Wait()
end

local function tweenUI(Time, Style, Direction, Goal)
	local info = TweenInfo.new(Time, Enum.EasingStyle[Style], Enum.EasingDirection[Direction], 0, false, 0)
	local info2 = TweenInfo.new(.2, Enum.EasingStyle[Style], Enum.EasingDirection[Direction], 0, false, 0)
	coroutine.wrap(function()
		local Tween1 = TweenService:Create(
			script.Parent.Frame,
			info,
			{BackgroundTransparency = Goal[2]}
		)
		Tween1:Play()
		Tween1.Completed:Wait()

		local Tween2 = TweenService:Create(
			script.Parent.Frame,
			info,
			{BackgroundColor3 = Goal[1], BorderColor3 = Goal[1]}
		)
		Tween2:Play()
		Tween2.Completed:Wait()

		ReplicatedStorage.PortalEvent:FireServer("Teleport", Part, IdentifierToSend)

		local Tween3 = TweenService:Create(
			script.Parent.Frame,
			info,
			{BackgroundTransparency = Goal[2] + 1}
		)
		Tween3:Play()

		tweenCamera(.5, "Sine", "InOut", 70)
	end)()
end

ReplicatedStorage.PortalEvent.OnClientEvent:Connect(function(Argument, PartName, Identifier)
	if not Argument or not PartName then return end
	if Argument == "manipulateCamera" then
		if PartName == "BluePortal"..Identifier then
			Part = "OrangePortal"..Identifier
			IdentifierToSend = Identifier
			script.Parent.Frame.BackgroundColor3 = Blue
			script.Parent.Frame.BorderColor3 = Blue
			tweenUI(1, "Sine", "InOut", {Orange, 0})
		elseif PartName == "OrangePortal"..Identifier then
			Part = "BluePortal"..Identifier
			IdentifierToSend = Identifier
			script.Parent.Frame.BackgroundColor3 = Orange
			script.Parent.Frame.BorderColor3 = Orange
			tweenUI(1, "Sine", "InOut", {Blue, 0})
		end
		tweenCamera(.5, "Sine", "InOut", 120)
		tweenCamera(.5, "Sine", "InOut", 0)
	end
end)

I also have a module for the player that might be part of where the error is coming from:

local module = {}

function module:Freeze(Player)
	Player.Character.Humanoid.WalkSpeed = 0
	Player.Character.Humanoid.UseJumpPower = true
	Player.Character.Humanoid.JumpPower = 0
end

function Unfreeze(Player)
	Player.Character.Humanoid.WalkSpeed = 16
	Player.Character.Humanoid.UseJumpPower = true
	Player.Character.Humanoid.JumpPower = 50
end

return module

If you think you know what I did wrong, pls let me know. Thank you in advance for your help.

Why not module:Unfreeze(Player)

1 Like

I changed that, but it still didn’t work. The camera tween is a lot smoother though.

I don’t know if this would help or not, but here’s another tween script that might be part of the problem.

local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local RemoteEvent = script.Parent:WaitForChild("RemoteEvent", 60)
local Count = 0

local pos1
local pos2

local Mouse = require(ReplicatedStorage:WaitForChild("Mouse")).new()

local EXTRASPIN = CFrame.fromEulerAnglesXYZ(math.pi / 2, 0, 0)
local ROTATE = CFrame.fromEulerAnglesXYZ(0, math.pi, 0)

local function getRotationBetween(u, v, axis)
	local dot, uxv = u:Dot(v), u:Cross(v)
	if (dot < -0.99999) then return CFrame.fromAxisAngle(axis, math.pi) end
	return CFrame.new(0, 0, 0, uxv.x, uxv.y, uxv.z, 1 + dot)
end

local function getSurfaceCF(part, lnormal)
	local transition = getRotationBetween(Vector3.new(0, 1, 0), lnormal, Vector3.new(0, 0, 1))
	return part.CFrame * transition * EXTRASPIN
end

script.Parent.Activated:Connect(function()
	if not Player.IsTeleporting.Value then
		if Count == 0 then
			Count += 1
			pcall(function()
				pos1 = Mouse.Hit.Position
			end)
			if not pos1 then return end
			local target = Mouse.Target
			local surfaceCF = getSurfaceCF(target, target.CFrame:VectorToObjectSpace(Mouse.TargetSurfaceNormal)) - target.Position
			local Velocity = (
				(script.Parent.Parent.Humanoid.TargetPoint -
					script.Parent.Parent.Head.Position
				).Unit
			) * 75
			RemoteEvent:FireServer(Velocity, pos1, surfaceCF)
			script.Parent.Sound:Play()
		elseif Count == 1 then
			Count = 0
			pcall(function()
				pos2 = Mouse.Hit.Position
			end)
			if not pos2 then return end
			local target = Mouse.Target
			local surfaceCF = getSurfaceCF(target, target.CFrame:VectorToObjectSpace(Mouse.TargetSurfaceNormal)) - target.Position
			local Velocity = (
				(script.Parent.Parent.Humanoid.TargetPoint -
					script.Parent.Parent.Head.Position
				).Unit
			) * 75
			RemoteEvent:FireServer(Velocity, pos2, surfaceCF)
			script.Parent.Sound:Play()
		end
	end
end)

It might be a part thats blocking the camera or smth…

1 Like

I don’t think so. Whenever I play the game and the tween starts playing, the camera shakes a slight bit and zooms in on my avatar’s head and won’t zoom out. When this happens, I can’t even move, which I think is part of my module’s code from whenever it was called. I think it may be something in my sever script:

local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerStorage = game:GetService("ServerStorage")
local HumanoidHandler = require(ServerStorage:WaitForChild("HumanoidHandler", 60))

Players.PlayerAdded:Connect(function(Player)
	if not workspace:FindFirstChild("PortalGunFolder"..Player.Name) then
		local PortalGunFolder = Instance.new("Folder")
		PortalGunFolder.Name = "PortalGunFolder"..Player.Name
		PortalGunFolder.Parent = workspace
	end

	local Debounce = Instance.new("BoolValue")
	Debounce.Value = false
	Debounce.Name = "PortalDebounce"
	Debounce.Parent = Player

	local CanTeleport = Instance.new("BoolValue")
	CanTeleport.Value = false
	CanTeleport.Name = "CanTeleport"
	CanTeleport.Parent = Player

	local IsTeleporting = Instance.new("BoolValue")
	IsTeleporting.Value = false
	IsTeleporting.Name = "IsTeleporting"
	IsTeleporting.Parent = Player

	local CFrameCheck = Instance.new("StringValue")
	CFrameCheck.Name = "CFrameCheck"
	CFrameCheck.Value = 0
	CFrameCheck.Parent = Player

	Player.CharacterAdded:Connect(function(Character)
		Character.Humanoid.UseJumpPower = true
	end)
end)

ReplicatedStorage.PortalEvent.OnServerEvent:Connect(function(Player, Argument, PartName, Identifier)
	if not Player or not Argument or not PartName then return end
	if Argument == "Teleport" then
		local Part = workspace["PortalGunFolder"..Identifier]:FindFirstChild(PartName)
		if Part then
			Player.Character.HumanoidRootPart.CFrame = CFrame.new((Part.CFrame * Part.CFrame.Rotation).p + Vector3.new(0, 5, 0), Vector3.new(0, 0, 0))
			HumanoidHandler:Unfreeze(Player)
			task.wait(3.5)
			Player.IsTeleporting.Value = false
			Player.CanTeleport.Value = true
		elseif not Part then
			Player.IsTeleporting.Value = false
			Player.CanTeleport.Value = true
			HumanoidHandler:Unfreeze(Player)
		end
		task.wait(.5)
		if Player.Character.HumanoidRootPart.CFrame == Player.CFrameCheck.Value then
			Player.IsTeleporting.Value = false
			Player.CanTeleport.Value = true
			HumanoidHandler:Unfreeze(Player)
		else
			warn(Player.Character.HumanoidRootPart.CFrame)
			warn(Player.CFrameCheck.Value)
		end
	end
end)

Players.PlayerRemoving:Connect(function(Player)
	if workspace:FindFirstChild("PortalGunFolder"..Player.Name) then
		workspace["PortalGunFolder"..Player.Name]:Destroy()
	end
end)

Maybe because of this??? Maybe it is, because you are setting the FOV to 0

1 Like

That wasn’t it. It did make the camera not go into my head, which I guess is good.

I’ve tried adjusting a few things, but I still can’t get it to work.

Can someone please help me figure this out?