Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Code to change CameraSubject not working?

Asked by 5 years ago
Edited 5 years ago

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.

0
you have to change the CameraType to scriptable first theking48989987 2147 — 5y
0
how? NickIsANuke 217 — 5y

1 answer

Log in to vote
0
Answered by
royaltoe 5144 Moderation Voter Community Moderator
5 years ago

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")
0
But it only happens when a round starts NickIsANuke 217 — 5y
0
one sec NickIsANuke 217 — 5y
0
Ok I made my question more relevant NickIsANuke 217 — 5y
0
Then have a remote function which you fire to the players once the round starts royaltoe 5144 — 5y
View all comments (5 more)
0
Wut NickIsANuke 217 — 5y
0
IDK what a remote function is XD NickIsANuke 217 — 5y
0
do you know what remote events are? royaltoe 5144 — 5y
0
ok, i can explain it to you over discord or in the site chat if you'd like royaltoe 5144 — 5y
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? royaltoe 5144 — 5y
Ad

Answer this question