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

Using RemoteEvents, why isn't the players local script firing from the server?

The title explains most of the issue, but I'll explain a little further.

The purpose of this script setup is to replace the player's character to a model inside the Workspace and set the player's CurrentCamera to be relatively where that model is (but its set to a different part, which is considered the actual camera.)

The server script is inside of a part which fires a RemoteEvent once it gets touched. Here's that script.


script.Parent.Touched:connect(function(object)
	local char = object.Parent
	local player = game.Players:GetPlayerFromCharacter(char)
	char:Destroy()
	player.Character = script.Parent.Parent.Pilot
	--Script from this point handles camera management with FE enabled.
	local event = Instance.new("RemoteEvent")
	event.Parent = script.Parent
	event.Name = "cameraPilot"
	event:FireClient(player)
	
end)

Next off, the local script that receives the firing request. Since camera manipulation can only work within a local script inside the player, I found this to be the easiest way to do it, with FE enabled.

local player = game.Players.LocalPlayer

player:WaitForChild("cameraPilot").OnClientEvent:connect(function()
	print("Connection successful. Adjusting Camera.")
	local cam = workspace.CurrentCamera
	cam.CameraType = Enum.CameraType.Track
	cam.CameraSubject = workspace["Mig-35"].pilotStuff.cameraPilot
end)

I've checked over it many times and I still can't figure out the issue. I would love some help ahaha Thanks guys :)

P.S: My bird in my room is chirping so much that its pissing me off and this might not have been explained thoroughly, sorry...

1 answer

✓ Accepted answer

The Issue

I knew what is wrong. In the LocalScript, the script is trying to wait for "cameraPilot" RemoteEvent which is in the LocalPlayer. However, in the Server Script, you inserted the RemoteEvent into a part.

Use ReplicatedStorage

In my opinion, you should use ReplicatedStorage to store your RemoteEvents and even RemoteFunctions.

Let's fix your code, shall we?

Server Script:

script.Parent.Touched:connect(function(object)
    local char = object.Parent
    local player = game.Players:GetPlayerFromCharacter(char)
    char:Destroy()
    player.Character = script.Parent.Parent.Pilot
    --Script from this point handles camera management with FE enabled.
    local event = Instance.new("RemoteEvent", game.ReplicatedStorage) -- You just have to provide the new instance's parent as the second argument.
    event.Name = "cameraPilot"
    event:FireClient(player)
    event:Destroy() -- This is optional! Delete this line if not necessary. It just deletes the event object.
end)

LocalScript:

local rs = game.ReplicatedStorage -- Reference to ReplicatedStorage.

rs:WaitForChild("cameraPilot").OnClientEvent:connect(function() --Waits for the RemoteEvent in ReplicatedStorage.
    print("Connection successful. Adjusting Camera.")
    local cam = workspace.CurrentCamera
    cam.CameraType = Enum.CameraType.Track
    cam.CameraSubject = workspace["Mig-35"].pilotStuff.cameraPilot
end)

If you have any problems, please leave a comment below. Thank you and I hope this will help you!

1 comment

0

I found this out after doing some more research. I really appreciate the confirmation though!!

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