Need help with tool script

what i want: When i activate the tool a part appears
when u touch the part the person who touched will have their camera scriptable and be looking at the part BUT if the local player touches it nothing will happen since they activated it

normal script inside tool:

local tool = script.Parent

local rep = game:GetService("ReplicatedStorage")

local part = rep:WaitForChild("Part")

local  rem = rep:WaitForChild("RemoteEvent")

local rem2 = rep:WaitForChild("rem2")


rem.OnServerEvent:Connect(function(plr)
	
	local Char = plr.Character or plr.CharacterAdded:Wait()
	

	local hum = Char:FindFirstChild("Humanoid")
	
	local Head = Char:FindFirstChild("Head")
	
	local CLONE = part:Clone()

	CLONE.Parent = workspace
	
	CLONE.CFrame =  Head.CFrame * CFrame.new(0,0,-10)
	
	
	local deb = false 
	CLONE.Touched:Connect(function(hit)
		
		if deb then return end
		
		if hit.Parent ~= plr and plr.Name  then
			
			deb = true
			
			rem2:FireAllClients(hit.Parent)
		
			
			task.wait(3)
			
			deb = false
			
			
		end
	end)
end)

local script inside startercharacterscripts:

local rep = game:GetService("ReplicatedStorage")

local  rem2 = rep:WaitForChild("rem2")

local cam = workspace.CurrentCamera

rem2.OnClientEvent:Connect(function(plr,hitparent)

	cam.CameraType = Enum.CameraType.Scriptable

	cam.CFrame = game.Workspace.Part.CFrame

	print("ok")
end)

in this line you are telling the script to ignore the player who made the part

in this line you are sending to EVERY client in the server meaning everyone in the server will have their camera scripted

1 Like
FireClient: player argument must be a Player object 

youre checking if the parent of β€œhit” is a player value. Instead you should do something like

if hit.Parent ~= char then --makes sure the hit players character isnt the player who activated it

this should be

local hitPlayer = game.Players:GetPlayerFromCharacter(hit.Parent)
rem2:FireClient(hitPlayer)

you need a player argument for the fireclient function so the script knows which specific player client to fire to. The game.Players:GetPlayerFromCharacter() function gets the player object from a character (if the character is a player) and assuming if the parent of hit is a character model this built in function will retrieve the player from that character.

Also, fire all clients doesnt need a player argument because its firing to every single client in game.

Hope this helps!

1 Like

what about the local script in starter charracter

local rep = game:GetService("ReplicatedStorage")

local  rem2 = rep:WaitForChild("rem2")
local cam = workspace.CurrentCamera
rem2.OnClientEvent:Connect(function(plr,hitparent)
	cam.CameraType = Enum.CameraType.Scriptable
	hitparent.cam.CFrame = game.Workspace.Part.CFrame
	print("ok")
end)

you dont need these arguments because the script fires to that specific client so you can write things normally

this should just be cam cause as i said it fires to the specific client so the player that touched the parts camera will be effected.