Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Code to change CameraSubject not working?

I made a piece of code in a script that should change the CameraSubject to a model that I have inside the player. It doesn't work, no errors. Code:

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local ServerStorage = game:GetService("ServerStorage")

local MapsFolder = ServerStorage:WaitForChild("Maps")

local Status = ReplicatedStorage:WaitForChild("Status")

local GameLength = 120

local IntermissionLength = 10

local secValue = ReplicatedStorage:WaitForChild("Seconds")

local playersLeft = 0

--Badge

id = 2124480512
function onPlayerEntered(newPlayer)
print("Giving Badge"..id.."To Player"..newPlayer.Name..".")
local b = game:GetService("BadgeService")
b:AwardBadge(newPlayer.userId,id)
end

game.Players.PlayerAdded:connect(onPlayerEntered)

--Leaderstats

game.Players.PlayerAdded:Connect(function(player)
	
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player
	
	local debris = Instance.new("IntValue")
	debris.Name = "Debris"
	debris.Parent = leaderstats
	
end)

--Main loop

while true do
	
	game.Lighting.ClockTime = 12
	
	secValue.Value = "--"
	
	--[[if game.Players.NumPlayers <= 1 then
		Status.Value = "Waiting for players."
		
		repeat wait(1) until game.Players.NumPlayers >= 2
	end --]]
	
	Status.Value = "Intermision."
	
	for seconds = IntermissionLength,0,-1 do
		secValue.Value = seconds
		wait(1)
	end
	
	local Maps = MapsFolder:GetChildren()
	local Map = Maps[math.random(1,#Maps)]
	
	local ClonedMap = Map:Clone()
	ClonedMap.Parent = workspace
	ClonedMap.Name = "Map"
	
	Status.Value = "The "..Map.Name.." has been chosen"
	for secsForMap = 4,0,-1 do
		secValue.Value = secsForMap
	end
	
	local SpawnPoints = ClonedMap:FindFirstChild("SpawnPoints")
	local AvailableSpawns = SpawnPoints:GetChildren()
	
	for i, player in pairs(game.Players:GetPlayers()) do
		if player then
			character = player.Character
			
			if character then
				
				--Teleport
				
				character:FindFirstChild("HumanoidRootPart").CFrame = AvailableSpawns[1].CFrame + Vector3.new(0,12,0)
				table.remove(AvailableSpawns, 1)
				
				--Morph
				
				for _,v in pairs(character:GetChildren()) do
					if v:IsA("BasePart") then
						v.Transparency = 1
					elseif v:IsA("Accessory") then
						v:Destroy()
					end
					
					if character:FindFirstChild("Head"):FindFirstChild("face") then
						character.Head.face:Destroy()
					end
				end
				
				local Morph = game:GetService("ServerStorage").DefaultTornado
				local ClonedMorph = Morph:Clone()
				ClonedMorph.Parent = character
				ClonedMorph.Name = "Morph"
				
				character.HumanoidRootPart.Size = character.HumanoidRootPart.Size + Vector3.new(0,58,0)
				
				local MyWeld = Instance.new("Weld")
				MyWeld.Parent = ClonedMorph.TornadoPart
				MyWeld.Part1 = ClonedMorph.TornadoPart
				MyWeld.Part0 = character.HumanoidRootPart
				
				wait()
				
				-- Speed
				
				character.Humanoid.WalkSpeed = Morph.Speed.Value
			end
		end
	end
	
	game.Workspace.Camera.CameraType = Enum.CameraType.Scriptable
	game.Workspace.Camera.CameraSubject = character:FindFirstChild("Morph")
	
	Status.Value = "Game in progress."
	
	print("Game started")
	
	for i = GameLength,0,-1 do
		
		secValue.Value = i
		
		--[[if game.Players.NumPlayers <= 1 then
			print("Not enough players left.")
			break
		elseif i == 0 then
			print("Time's Up")
			break
		end --]]
		
		wait(1)
		
	end
	
	print("Game over. Initializing cleanup.")
	
	Status.Value = "The game has ended. Initializing cleanup."
	
	secValue.Value = "--"
	
	for i, player in pairs(game.Players:GetPlayers()) do
		character = player.Character
		
		if character then
			if character:FindFirstChild("Morph") then
				character.Morph:Destroy()
			end
		end
		
		player:LoadCharacter()
		
		character.Humanoid.WalkSpeed = 20
	end
	
	ClonedMap:Destroy()
	
	wait(4)
	
end

PS. The Camera setting is on line 124.

2 comments

0

you have to change the CameraType to scriptable first

0

how?

1 answer

Make a reference to the localplayer's character and change the camera's camera type to scriptable. You should put this in the starterCharacter

character = game.Players.LocalPlayer.Character
game.Workspace.CurrentCamera.CameraType = Enum.CameraType.Scriptable
game.Workspace.Camera.CameraSubject = character:FindFirstChild("Morph")

9 comments

0

But it only happens when a round starts

0

one sec

0

Ok I made my question more relevant

0

Then have a remote function which you fire to the players once the round starts

0

Wut

0

IDK what a remote function is XD

0

do you know what remote events are?

0

ok, i can explain it to you over discord or in the site chat if you'd like

0

Hi, you've been online since I last posted, but you seem to not have the question answered. Do you still need this answer to be answered or does the code above work?

This discussion is preserved as it was. New answers, comments, and votes are closed.