In many systems I created I always dodge this problem or by using remote events/functions or Modules.
But… by very last time, I just wanna know if there’s a chance of doing this:
Theres a Part welded on Player1 Head, theres a ClickDetector with a Server Script in it.
A Player2 clicks that Part on Player1. (There is Local Scipts inside Player2)
Is there a way that the Server Script inside that Player1’s Part, can read a Variable inside the Player2 who clicked the Player1’s Part? like:
(this is a dumb example I know xD)
Server Script inside Player1’s Part
local function clicked(player2)
print(player2.PlayerScripts.LocalScript.Var)
end
click.MouseClick:Connect(clicked)
Local Script inside Player2
Global Var = "cmon!"
After research looks like its impossible… But… Im a fool and I would wish easy stuff like this to make things faster :v
So any way?
Thank you for your time :3
The client-to-client communication is the standard usage of remotes. Firing during the click is used during the time it was clicked. This is always after the action was done.
Firing during the click is better. You fire the variable to the first player and the variable is sent. Note that the server script can’t read changes of a client. The variable cannot be read as different by server if Player2 decided to change it. Player2 has to fire an event to send their variable rather than from a value object.
Firing during the click… Fire the variable to the first player and the variable is sent?
How?.. A very little example? :v
The only ways I found is by using Remotes and Modules to share variables among Scripts in all Server. The @EngiAdurite answer and yours sounds to me like, “again its only possible by using Remotes”
Waa Im lazy… and Im getting tired of bunchs of Remotes everywhere for many simple stuff… I really love Roblox engine, but, there’s other engines where you can access Variables inside other “colliding/interacted” objects. But looks like in Roblox is not possible. Only by using Remotes or storing variables in Modules
In this function, use a RemoteEvent, fire the event to the player who owns the part(assuming that it was mounted and parented to the first player) and send the other player’s variable. The other player’s variable has to be fired too, to get an accurate variable from the other player as well, if the intention is that the variable is to be changed by the other player.
Depending on your exact use case, it may be possible to use _G or even string values, however I would highly suggest using remotes as the others here have said, I’m not sure why you’re shying away from it.
If you’re still not getting it, there’s only one remote that is placed in ReplicatedStorage, which is the most convenient and canonical storage for such objects. We can change the clicking event to client anyways.
-- Local script
local function onClicked(player2)
SendVariable:FireServer(variable)
end
click.MouseClick:Connect(clicked)
SendVariable.OnClientEvent:Connect(function(variable)
print(variable) -- here goes the variable
end)
Warning: This may have unforeseen consequences if it was bad user input, you should sanitize(and filter) the server when it receives it. This is only the base.
-- Server script, assume you have a variable for the owner of the part.
SendVariable.OnServerEvent:Connect(function(player, variable)
SendVariable:FireClient(owner, variable)
end)
Yup. I agree about that. Thats what I do on all cases required. Just using Remote events. I understand ur example.
So yes, the only option is keep using remote events, even if its just a quick basic thing to do in the system. Thank you, what u say is true
Yup I think thats the problem. Im getting lots of Remote Events while progresin on a project… Well I learned to be more organized and rehuse the Events as far as I can while having sense and dont mess the functions… like fusing or something…
But Im still getting lots of remotes, functions, even for something so simple like reading a variable inside someone head’s carrying an object… or I implement Modules to share variables across the server or I implement remote events… So yeah… why not only reach that player’s script and find his variable on touch…?
I gotta learn to be more organized thats true!!! :3