Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Onclicked remote server event?

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!

3 comments

0

Should work. Also, you should use server scripts when detecting clicks w/ click detectors

0

I'm sorry but what???

0

yeah, it should work?

1 answer

✓ Accepted answer

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)

2 comments

0

I'm going to test it

0

Thanks so much dude, it worked!

This discussion is preserved as it was. New answers, comments, and votes are closed.