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

Change camera when gui button pressed?

Asked by 5 years ago

Im using that script,its a local inside the button (GUI button) Something is wrong,it isnt working.

function onButton1Down()
game.Players.LocalPlayer.Character.Torso.CFrame=CFrame.new(Vector3.new(0,150,0))-- Teleport
wait()
    local Ncam=Workspace.Camera
    Ncam.CameraSubject=game.Players.LocalPlayer.Character.Humanoid
    Ncam.CameraType="Custom"
wait(0.2)
script.Parent.Parent.Parent.Parent.Parent.Backpack.CamFix:remove()
script.Parent.Parent.Parent:remove()
end

script.Parent.MouseButton1Down:connect(onButton1Down)
0
local Ncam=workspace.CurrentCamera F_F 53 — 5y
0
connect, remove are deprecated, use Connect and Destroy. Also, use Enum.CameraType.Custom, not "Custom". Use more variables as well. User#19524 175 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

Did you used a free model cause there is a bunch of deprecated things in this script..?

Fix:

-- Local Script
local Player = game:GetService("Players").LocalPlayer

function Clicked()
Player.Character:SetPrimaryPartCFrame(CFrame.new(0, 150, 0)) -- Teleports player

wait(.1)

local Camera = Player.CurrentCamera

Camera.CameraSubject = Player.Character.Humanoid

Camera.CameraType = Enum.CameraType.Custom

wait(0.2)
Player.Backpack:WaitForChild("CamFix"):Destroy() -- :remove() is deprecated 

script.Parent.Parent.Parent:Destroy()

end

script.Parent.MouseButton1Click:Connect(Clicked)
0
I always use remove().. SpringtraPlayer 16 — 5y
0
Well dont do it, its deprecated ;) AswormeDorijan111 531 — 5y
Ad

Answer this question