(I tried using Remote Events and Functions, though I might've done something wrong.) What I want to do is use a LocalScript ability (LocalPlayer) to make a variable for something a script might do. Here is an example of what I want to do:
p = game.Players.LocalPlayer.HumanoidRootPart
(That line of code was in a normal script, and i want to put that into a Local script and use a linking event to allow the use of this variable into the normal script without an error.)
However, i also want to cause a function to happen when these two Humanoids touch. I tried using OnTouched, Touch:connect, it wont happen. Can someone please help me with these two situations?
Yes, that is possible. Though, you can't send from ServerScript to LocalScript but you can do the opposite. Please remember, LocalScripts
are for GUIs, while ServerScripts
are for physical objects. Never do the opposite. Also, I bet you will know how to get around the problem by using StarterCharacterScripts
since it seems like you are messing with the character.
Lastly, before I start you can't do game.Players.LocalPlayer
inside a ServerScript. You will have to receive player in a certain way. game.Players.PlayerAdded:Connect(function(plr)
or remote events etc.
There are 2 ways to do this:
ModuleScript or RemoteEvents
In a LocalScript
, you can send a variable to a server script.
Like so:
local color = 'Blue' local RE = game:GetService('ReplicatedStorage'):WaitForChild('ColorEvent') RE:FireServer(color)
now you can send more then 1 variable and you can do RE:FireServer inside functions
local color = 'Blue' local RE = game:GetService('ReplicatedStorage'):WaitForChild('ColorEvent') Button.MouseButton1Down:Connect(function() RE:FireServer(color) end)
from a ServerScript
this is how you receive the data, note that player is automatically defined by RE:FireServer()
.
ServerScript:
local RE = game:GetService('ReplicatedStorage'):WaitForChild('ColorEvent') RE.OnServerEvent:Connect(function(plr, blue) -- plr always comes first, if you put blue then blue is plr -- code end)
Or from a module script you can make a entire dictionary full of what each variable is and require it.
Here are some link if you still don't understand:
https://www.youtube.com/watch?v=qrulMMc0cNI
http://wiki.roblox.com/index.php?title=API:Class/ModuleScript&redirect=no
https://www.youtube.com/watch?v=4Dc_bri9mjs
http://wiki.roblox.com/index.php?title=API:Class/RemoteEvent
http://wiki.roblox.com/index.php?title=Remote_Events_and_Functions
Now there may be more ways but these 2 are probably the most popular ways as they are simple. If this helped you in anyway, please Upvote and accept answer
-- Your Orange, BlackOrange3343 PS: Good luck