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

camera manipulation in server script?

local this = script.Parent.Parent.detector
local db = false


this.Touched:connect(function(hit)
	
		if hit.Parent:FindFirstChild("Humanoid") ~= nil then
			local char = hit.Parent
			local plr = game.Players:WaitForChild(char.Name)
			local cam = game.Workspace.CurrentCamera
			cam.CFrame = this.Parent.Parent.camparts.cam1.CFrame
			cam.CameraType = Enum.CameraType.Scriptable
			cam.CameraSubject = this.Parent.Parent.camparts.cam1
			
	-- Create a camera change, a close button to that and a way to detect if the shop is open, Be Patient :) it will take a while --

		end
			end)

I need it to be a server script to detect a player touching it but also i need the player who touched its camera to change please help.

1 answer

✓ Accepted answer

with Filtering Enabled on which I'm guessing you're using, as you haven't stated otherwise. You want to use a remote function in ReplicatedStorage

This is the Server script.

local this = script.Parent.Parent.detector
local db = false
local remoteEvent = game:GetService("ReplicatedStorage"):FindFirstChild("RemoteEvent")
--[[ 
ReplicatedStorage is the gateway between the client and the server, it's where

you want to store your remote events 
--]]

this.Touched:connect(function(hit)

        if hit.Parent:FindFirstChild("Humanoid") ~= nil then
		local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
		remoteEvent:FireClient(player,this.Parent.Parent.camparts.cam1.CFrame,this.Parent.Parent.camparts.cam1)
		--[[ 
		Get the player from the character, then fire the remote event, you need the player
		
		so that the remoteEvent knows which player triggered the event.
		--]]
	end

    -- Create a camera change, a close button to that and a way to detect if the shop is open, Be Patient :) it will take a while --

end)

Local Script

You can put this in the StarterGui


script.Parent.RemoteEvent.OnServerEvent:Connect(function(player, positioning, subject)
	
	local char = hit.Parent
	local plr = game:GetService("Players").LocalPlayer
	local cam = game.Workspace.CurrentCamera
	cam.CFrame = positioning
	cam.CameraType = Enum.CameraType.Scriptable
	cam.CameraSubject = subject

end)


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