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

Why doesn't the server script always give the value "nil" to the client?

This is the first client script

TransformEv = game.ReplicatedStorage.Events:FindFirstChild("TransformEv")
local pobo = 2
UserInputService.InputBegan:connect(function(input,gameProcessed)
if input.UserInputType == Enum.UserInputType.Keyboard and not gameProcessed then
if input.KeyCode == Enum.KeyCode.F then
 	 TransformEv:FireServer({Type = "Transform",Choice = pobo}) 
end
end
end)

It sends the value to the server script

local CameraChange = game.ReplicatedStorage.Events.CameraChange
game.ReplicatedStorage.Events.TransformEv.OnServerEvent:connect(function(player,args)
local char = player.Character
if args.Type == "Transform" then
	local Stats = player:WaitForChild("Stats")
	local OtherPlayer = args.Choice
	Stats.Transformed.Value = true
	CameraChange:FireClient(player,OtherPlayer)
end
end)

Then it sends it back to the other client script

local CameraChange = rs.Events:WaitForChild("CameraChange")
function CameraOnPlayer(player,OtherChar)
	cam.CameraSubject = workspace:FindFirstChild(OtherChar):FindFirstChild("Torso")
end
CameraChange.OnClientEvent:Connect(CameraOnPlayer)

The problem is the server script won't give the value to the client. I printed it and the server does have the value but every time I try and send the value to the client it is nil.

1 answer

✓ Accepted answer

The issue is actually pretty simple. FireClient does not pass the player that the RemoteEvent/RemoteFunction is called for. This is why LocalPlayer exists, to tell you who is the local client. Removing the player argument should fix the issue.

local CameraChange = rs.Events:WaitForChild("CameraChange")
function CameraOnPlayer(OtherChar)
    cam.CameraSubject = workspace:FindFirstChild(OtherChar):FindFirstChild("Torso")
end CameraChange.OnClientEvent:Connect(CameraOnPlayer)

1 comment

0

I love you, Thank you.

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