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

How can I pass a LocalScript through a Server Script via tool:activated:connect() ?

Asked by 3 years ago

I'm trying to put Path Givers in my game, and whilst they work fine they are only visible to the player who is creating the Paths. I googled a fix to this and I say someone say on the DevForums that I could pass the Tool's LocalScript through a Server Script by using 'tool:activated:connect()'

Since I'm fairly new to coding I'm not entirely sure how I can do this, can anybody help me understand what I need to do?

0
Can you explain what "path givers" are? Anyway, so what I see here is you want communication between a LocalScript and a Script, you can do this via RemoteEvents. You can look into remote events here: https://developer.roblox.com/en-us/articles/Remote-Functions-and-Events#client-to-server MarkedTomato 810 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

You should use Remote Events to connect a Server script to Local script and vice versa.

I'll make a little example of how to use it with a tool:

--local script:

local text = 'WOW!'
local event = game:GetService('ReplicatedStorage').RemoteEvent

local tool = script.Parent

tool.Activated:Connect(function()
   event:FireServer(text)
end)

--server script:

local event = game:GetService('ReplicatedStorage').RemoteEvent

event.OnServerEvent:Connect(function(plr, text)
   print(text)
end)
Ad

Answer this question