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

Unable to pass values in remote event?

Hello. I got a script that deactivates parts, but the problem isn't with that, it was with the script not passing the value of the arguments into the remote event

game:GetService("ReplicatedStorage"):FindFirstChild("PartDeactivator"):FireClient(game.Players:GetPlayerFromCharacter(hit.Parent),"activate")

so the 2nd argument is "activate"

game:GetService("ReplicatedStorage").TrussActivator.OnClientEvent:Connect(function(player,type)
	
	print(type)
	local trussToActivate = game.Workspace.Obby.Obstacles["12"].ActivatedTrusses:GetChildren()
	if type == "activate" then
		for i, truss in pairs(trussToActivate) do
			if truss:IsA("TrussPart") and not truss:IsA("Script") then
				wait(0.001)
				truss.CanCollide = true
				truss.Transparency = 0
			end
		end
	elseif type == "deactivate" then
		for i, truss in pairs(trussToActivate) do
			if truss:IsA("TrussPart") and not truss:IsA("Script") then
				wait(0.001)
				truss.CanCollide = false
				truss.Transparency = 1
			end
		end
	end
end)

so the line that prints out type, it didn't print out "activate", it printed out "nil"

and because of that the rest of my script does not run

any idea why the value is nil? I really need help

thanks for your time and answers are greatly appreciated

2 comments

0

'type' is a built-in function that returns the type of the given value, and you named one of your variables 'type'. Consider alternatives, such as 'signalType' or 'stringType'.

0

@DeceptiveCaster , I changed the argument name to another name, yet it stills prints out "nil"

1 answer

✓ Accepted answer

Extending upon what I had previously said, player is assigned to "activate" but type is nil because it has nothing assigned to it.

FireClient()'s parameters:

  • The player to fire the event to (required)

  • A tuple of arguments to pass, of which its length must agree with the event function's arguments.

When you used FireClient() you passed a player (which does not get sent to the receiving function) and "activate" (which got sent and was assigned to player). In my eyes, you need only one argument in the receiving function, not two.

1 comment

0

Thank you very much!

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