ModuleScripts and RemoteEvents mixing up parameters

I am trying to pass variables through RemoteEvent or ModuleScript parameters. But whenever i use the variables in the other script i will get errors like “leaderstats is not a valid member of Workspace.Part” even though i am using the plr variable and not the part variable. I tried changing from putting the parameters in the connect function to a normal function but that did no difference.

local module = require(game.ReplicatedStorage.Modules.Doors)

	module.Function(plr, script.Parent)

What is the code you are using within the module?
Can you try replacing the parameters received in the module to and printing out the result?

MODULE.Function = function(...)

I tried that and it said “server”. I then realized it wouldn’t work with a modulescript so i changed it to a remote event OnClient. And maybe i should have clarified that i’m trying to make a door get 0.5 transparency and CanCollide of if the player has a certain amount of money when joining the game.

This is the code in the script in the door:

game.ReplicatedStorage.Remotes.Money.MoneyNeededEvent:FireClient(plr, script.Parent)

This is the LocalScript in StarterGui:

game.ReplicatedStorage.Remotes.Money.MoneyNeededEvent.OnClientEvent:Connect(function(plr, part)
	if plr.leaderstats.Money.Value >= part.Value.Value then -- We have an intvalue in the part btw
		part.Transparency = 0.5
		part.CanCollide = false

the plr parameter is not passed when you call the player, so it should just be


This means you have to redefine the plr variable, which you can easily do at the top of the script with

local plr = game.Players.LocalPlayer

Also, i recommend adding a slight delay before calling the remote event, so the player has time to load

1 Like

Error: FireClient: player argument must be a Player object

You adjusted the wrong one
You edited

game.ReplicatedStorage.Remotes.Money.MoneyNeededEvent:FireClient(plr, script.Parent)

when you should have edited

game.ReplicatedStorage.Remotes.Money.MoneyNeededEvent.OnClientEvent:Connect(function(plr, part)

If the RemoteEvent is from LocalScript to Script what should i do since i can’t get LocalPlayer from a script.

Can you quickly send the server side script that receives the function call? (The :Connect(function() part of it)

This is another script because i am not doing the same thing right now but it’s the same problem just the other way. I am trying to make a trail equip when a button is clicked:

game.ReplicatedStorage.Remotes.EquipRemote.OnServerEvent:Connect(function(plr, item)

Your answer is already in there!

...OnServerEvent:Connect(function(plr, item)

when it is the client calling the server, the player variable is passed on. However, it isn’t when the server calls the client

It still doesn’t work. If i print(typeof(plr), plr) and print(typeof(item), item) it says both are the player. Here is the FireServer in the localscript btw:

game.ReplicatedStorage.Remotes.EquipRemote:FireServer(plr, game.ReplicatedStorage.Trails.White)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.