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

How to pass arguments involving players?

Asked by 8 years ago

I DO NOT want to use RemoteEvents, so please don't mention them as answers.

I just want to pass a player type into another script, but without using RemoteEvents. Is this possible? I came up with this code inside a Module Script:

mod = {}

mod.passVariable = function(plr)
print(plr.ClassName)
end)

return mod

Inside of another script:

p = game.Players.LocalPlayer
a = require(game.Workspace["Test Script"]
a.passVariable(p)


For some reason this doesn't work. Please help me out!

0
What do you actually want? Why do you need to "pass a player type into another script"? Is it a Script or a LocalScript? BlueTaslem 18071 — 8y

2 answers

Log in to vote
0
Answered by
Perci1 4988 Trusted Moderation Voter Community Moderator
8 years ago
Edited 8 years ago

Syntax errors

You just have a couple of 'em:


mod.passVariable = function(plr)
    print(plr.ClassName)
end)

On line three, the closing parenthesis is not needed.


a = require(game.Workspace["Test Script"]

Here, you forgot the closing parenthesis.



Make sure you're looking at the output, it will help you catch your syntax errors. If you fix these problems, it should work.

I'm not sure why you're so averse to remotes, however. They would also work in this scenario.

Ad
Log in to vote
0
Answered by 8 years ago

It seems like you want to be able to pass one variable, for instance the numeral 5 over to another script. This is where Remote Events WOULD have been extremely efficient and more useful, only if you wanted to use them. So, in one glance I can see a few errors in which could have possibly caused your error.

mod = {}

mod.passVariable = function(plr)
    print(plr.ClassName)
    return plr.ClassName
end --Where the parentheses would have been.

return mod

Now, the parentheses that you add at the end of 'end' was removed due to it not being needed, I also added a return after the print so we can use the function as a variable.

local p = game.Players.LocalPlayer
local a = require(workspace["Test Script"]) --Added in the parentheses, also changed game.Workspace to 'workspace', More efficient.
local var = a.passVariable(p) --Now returns a value, which we can use later on.

In my changes for the upper segment I have adding in the parentheses that you possibly forgot to implement, I also changed your variable to local variables as your variables were previously global, which slows down performance and were inefficient. Next, having respect for my first correction I reminded myself that we return the value when the function is called, so I changed the area where we call the 'passVariable' function to a variable so we can use the return value later on. I also changed 'game.Workspace' to 'workspace' as it saves space and is more efficient. Cheers!

Answer this question