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

Camera changes for every player instead of the one touching the part. What's the problem?

local shopPart = game.Workspace.BackpackPlatform

local function onTouch(partTouched)
	local prevCFrame = game:GetService("Workspace").Camera.CFrame
    local camType = game:GetService("Workspace").Camera.CameraType
	local price = script.Parent.Price
	local spaces = script.Parent.Spaces
	
	
	game:GetService("Workspace").Camera.CameraType = camType
	game:GetService("Workspace").Camera.CFrame = prevCFrame
	
	function MoveCamera(cframe, button)

    game:GetService("Workspace").Camera.CameraType = Enum.CameraType.Scriptable --Disables player moving camera

    game:GetService("Workspace").Camera.CFrame = cframe --Set camera position

	end
	price.Value = 350
	spaces.Value = 100
	MoveCamera(CFrame.new((game.Workspace.BackpackShopFrame.Item1.lvl1.Position)+Vector3.new(0,0,7)), script.Parent)
	
	script.Parent.TextLabel.Text = "Price: "..script.Parent.Price.Value
	game.Workspace.Teleport.RemoteFunction:InvokeServer()
	script.Parent.Parent.ShopCameraClose.Visible = true
	game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 0
	script.Parent.Parent.Parent.Stats.EXP.Visible = false
	script.Parent.Parent.Parent.Stats.Backpack.Visible = false
	script.Parent.TextLabel.Visible = true
	script.Parent.Next.Visible = true
	script.Parent.Parent.Buy.Visible = true
	script.Parent.Vector.Value = Vector3.new(47.015, 133.983, 54.438)
	
end
shopPart.Touched:Connect(onTouch)

So, when a player touches the shopPart, the camera changes for every player, is there a way to change it only to the player touching the part?

6 comments

0

Is this in a LocalScript? it should be... Make sure FilteringEnabled is on, and change "Camera" to "CurrentCamera"

0

Yes it is in a localscript, and FE is on. I'll try to change it to CurrentCamera and see if it works, thanks

0

Working! Thank you very much!

1

wow. did I just got my months old question, "Why do you type CurrentCamera and not Camera?"`answered?

0

lol, ur welcome!

0

Yeah use a LocalScript.

1 answer

✓ Accepted answer

Necessary Items:

A. FilteringEnabled set to true

This is to make sure that the game doesn't replicate all changes on the client to the server, making each player's changes unique (so if you died and the camera was reset it would not reset for all players)

B. Using a Local Script

To change a player's camera you must use a LocalScript since the camera is unique to each player, and changes to the server camera will not replicate (as it is not the same instance)

C. Using CurrentCamera

The workspace has an instance called "CurrentCamera" which on the client serves as the directional framing of the player's movement. The Camera cannot be directly edited from the server since the current camera is only local.

EXAMPLE

Change

game:GetService("Workspace").Camera

to

game:GetService("Workspace").CurrentCamera

For more on the Camera, see the below link:

https://developer.roblox.com/api-reference/class/Camera

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