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

How to get RemoteEvent working properly?

Workspace: Localscript>ClickDetector>Part

ReplicatedStorage: RemoteEvent

ServerScriptService: Script

The localscript:

script.Parent.MouseClick:Connect(function()
	game.ReplicatedStorage.PartClicked:FireServer()
end)

The script:

game.ReplicatedStorage.PartClicked.OnServerEvent:Connect(function()
	print("Hello")
end)

I can't seem to figure out/understand why it won't work.

2 answers

MouseClick() can only be handled using a script. See the description on ClickDetectors

So you don't need a remote event at all to check when a player clicks the part.

In the Script

game.Workspace.Part.ClickDetector.MouseClick:connect(function(playerThatClicked)
	print("Hello "..playerThatClicked.Name.."!")
end)

--Would Print:
--Hello xPolarium!

It should be like this,

REGULAR SCRIPT

local Event = game:GetService("ReplicatedStorage").PartClicked

script.Parent.MouseClick:Connect(function()
Event:FireServer()
end)

SERVER SCRIPT

local Event = game:GetService("ReplicatedStorage").PartClicked

Event.OnServerEvent:Connect(function()
print("Hello")
end)

2 comments

0

Still doesn't work because it's the same thing he has. Reason whyyy it doesn't work is because MouseClick() can't be used in a local script.

0

true,i fixed it

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