function test(var) print(var) end test("hello")
will print "hello"
How do I pass a value into an event e.g.
function test(p,var) print(var) end game.Players.PlayerAdded:Connect(test("hello"))
returns error
21:17:26.792 - Attempt to connect failed: Passed value is not a function 21:17:26.793 - Stack Begin 21:17:26.793 - Script 'Workspace.Script', Line 5 21:17:26.794 - Stack End 21:17:26.794 - attempt to call a nil value
Is it possible to pass values when calling a function like with the first example but with an event?
Thank you in advance to anyone that helps. If anything is unclear just leave a comment and I will try to explain.
your issue here that the argument passed for Connect
has to be a function. What you are doing is passing nothing. You are actually calling the test
function and getting it to print before it even connects to PlayerAdded
.
The fix for this is to make an entirely new function that will, in turn, fire your test
function
function test(p,var) print(var) end game.Players.PlayerAdded:Connect(function(player) test(player, "hello") end)
Notice how instead of calling the function (which would return nothing for the connection), I made an entirely new function that handles the connection and the print separately
Hope this helped!
game.Players.PlayerAdded:Connect(function() test("Arguments here") end)