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

Onclicked remote server event?

Asked by 6 years ago

Hello, I want it so if u click a part it will fire a remote then there gets something printed but it won't work ;/.

here is how its all positioned: http://prntscr.com/giaa7h here is the code: serverscript thingy:

local repStorage = game:GetService("ReplicatedStorage")
local remote = repStorage:WaitForChild("Remote")

remote.OnServerEvent:connect(function()
    print("SICK DUDE U CLICKED DA BRICK")
end)

the local script in the brick:

local repStorage = game:GetService("ReplicatedStorage")
local remote = repStorage:WaitForChild("Remote")

script.Parent.ClickDetector.MouseClick:connect(function()
    remote:FireServer()
end)

But now this does nothing HELP!

0
Should work. Also, you should use server scripts when detecting clicks w/ click detectors hiimgoodpack 2009 — 6y
0
I'm sorry but what??? DanielDeJong3 158 — 6y
0
yeah, it should work? aztec_glory 63 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

RemoteEvents are only used for client-server communication or vice-versa. Do not ever put a localscript as a descendant in workspace unless it's inside of a player's Character. Since both scripts are server-sided, you want to have both of them inside of a script.

local repStorage = game:GetService("ReplicatedStorage")
local remote = repStorage:WaitForChild("Remote")

script.Parent.ClickDetector.MouseClick:connect(function()
    print("SICK DUDE U CLICKED DA BRICK")
end)


If you really wanted to have communication between different scripts, use a BindableEvent

script 1:

local repStorage = game:GetService("ReplicatedStorage")
local bindable = repStorage:WaitForChild("BindableEvent")

script.Parent.ClickDetector.MouseClick:connect(function()
   bindable:Fire() -- fires bindable when clicked
end)


script 2:

local repStorage = game:GetService("ReplicatedStorage")
local bindable = repStorage:WaitForChild("BindableEvent")
bindable.Event:Connect(function() -- connects function when bindable is fired
    print("SICK DUDE U CLICKED DA BRICK")
end)
0
I'm going to test it DanielDeJong3 158 — 6y
0
Thanks so much dude, it worked! DanielDeJong3 158 — 6y
Ad

Answer this question