Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to send an object to a player's camera?

Asked by 6 years ago

I am trying to use a RemoteFunction to send an object to a player's camera. I understand a basic localscript with FilteringEnabled will do this trick, but the problem is, the object is something the player needs to pick up and obtain - not just be "seen". I tried this and the object to be picked up doesn't register.

So with that being said, I've been trying to send an object to a player's camera for the purpose so that only THEY can see the object and can interact with it and data actually saves, through a RemoteFunction.

Is there a better method rather than sending this to the player's camera?

Here is my failed script attempt:

game.ReplicatedStorage.rings.rings1.OnServerEvent:Connect(function(plrWhoFiredEvent)
    game.Lighting.rings:Clone().Parent = plrWhoFiredEvent.Camera
    wait(210)
    workspace.Camera.rings:Remove()
end)

I get the error "Camera is not a valid member of Player".

Thank you very much!

1 answer

Log in to vote
0
Answered by 6 years ago

Hey callmehbob,

In order for your part to become a Local Part, you need to place the Part inside of the Player's CurrentCamera. The only way to access the CurrentCamera, is through a LocalScript. Therefore, you need to use :FireClient() and fire the LocalScript to place the Part inside of the CurrentCamera, rather then the other way around like what you've been attempting. Also, it gave you the error saying that Camera isn't a valid member of Player because, the Camera is simply not an object inside of Player.

Anyways, now that I've done the explanation for what you need to do, I will give you below a personal example of how you will do this. I am not sure what you used to trigger these functions but, I'm going to just use the .Touched event of the Part to trigger it to become a Local Part.

Personal Example

---- LOCAL SCRIPT WHERE THE REMOTE EVENT FUNCTION HAPPENS ----
local rs = game:GetService("ReplicatedStorage")
local event = rs:WaitForChild("PickUp");

event.OnClientEvent:Connect(function(part)
    local cam = workspace.CurrentCamera;
    part.Parent = cam;
end)
---- SERVER SCRIPT WHERE THE REMOTE EVENT FUNCTION IS TRIGGERED ----
local part = script.Parent;
local plrs = game:GetService("Players");
local rs = game:GetService("ReplicatedStorage")
local event = rs:WaitForChild("PickUp");

part.Touched:Connect(function(obj)
    local hum = obj.Parent:FindFirstChild("Humanoid");
    if hum then
        local char = obj.Parent;
        local plr = plrs:GetPlayerFromCharacter(char);
        event:FireClient(plr, part);
    end
end)

Well, I hope I helped in one way or another and have a nice day/night.

~~ KingLoneCat

Ad

Answer this question