local function touched(touchingPart)
if touchingPart.Parent:FindFirstChild("Humanoid") then
print("ok")
local player = touchingPart.Parent
local cam = workspace.CurrentCamera
cam.CameraType = Enum.CameraType.Scriptable
local CF = game.Workspace.MarketCam.CFrame
cam.CFrame = CF
end
end
game.Workspace.MarCam.Touched:Connect(touched)
I have this code. But it’s not working I am not getting any errors. It’s supposed to change the players cameras CFrame
This needs to be ran on the client, since you’re changing their camera ( really hope you are );
Instead of making the player = to the hit.Parent ( super incorrect ) do this;
--//Services
local Players = game:GetService("Players")
--//Variables
local LocalPlayer = Players.LocalPlayer
--//Events
-- your event and code
local Player = Players:GetPlayerFromCharacter(touchingPart.Parent)
if Player == LocalPlayer then --makes sure you can actually change their camera and it was your local player on the client that hit the part
Anyways best of luck, hope this worked. If this was a server script, I’d highly recommend making it a local script and checking if the local player was the one who hit it, as the camera can only be changed locally for a player.
Yes, highly incorrect. When the player touches the part, it is not their player touching the part, it is their character that connected this event ( one of the parts in their character ). This is why you’re checking for a Humanoid, and doing part.Parent, because it was the character that did the event if a Humanoid exists. Which is why Roblox created GetPlayerFromCharacter to make it easier for you to get a player from their character ( instead of hypothetically having to do the event you did and or doing players:FindFirstChild(character.Name) ).