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)
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.