I keep getting 2 errors when trying to call values from a remote event " Type Error: (5,29) Unknown global ‘plr’ " and "Type Error: (5,34) Unknown global ‘UserinfoEvent’ "
Heres my code, am I just missing something?
Localscript :
local plr = game.Players.LocalPlayer
script.Parent.Parent.User:GetPropertyChangedSignal("Text"):Connect(function()
local UserinfoEvent = script.Parent.Parent.User.Text
local DirectedPlayer = game.Players:FindFirstChild(UserinfoEvent)
if game.Players[UserinfoEvent].Parent == game.Players then
Event:FireServer(plr, UserinfoEvent)
end
end)
ServerScript :
local Event = game.ReplicatedStorage.Fails.Checker
Event.OnServerEvent:Connect(plr, UserinfoEvent)
(below this doesnt matter since it wont run since the variables are an "unknown global")
That’s not how :Connect() works, :Connect() requires functions to return a Signal, It doesn’t just take in Variables, it never worked like that.
Remind me whenever you read about the functions and what they do.
This is basically what OnServerEvent does:
func(player: Player, ...any) -> () means function(), within the parenthesis is the Player Argument along with a Tuple (Ordered List) : RBXScriptConnection means it returns a Signal (or Connection)
RemoteEvent.OnServerEvent:Connect(function(Player, Arg1, Arg2)
end)
-- Alternative Route:
function Event(Player, Arg1, Arg2)
end
RemoteEvent.OnServerEvent:Connect(Event)
So when firing:
RemoteEvent:FireServer(Arg1, Arg2)
No, The Variable is not within the Scope of the Event, MEANING you CANNOT use it, because its unknown to the Code, You would use a Global Variable (not _G), but that would cause issues.