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

Can you fire Touched:Connect() from LocalScripts?

I have two scripts that detect if a tool comes into contact with a maintenance panel. It works fine if both are scripts, however I want the script in the tool to be Local, so I can fire a remoteevent with the player's name.

Local/ToolScript:

script.Parent:FindFirstChild("Handle").Touched:Connect(function(hit)
	if hit:FindFirstChild("Humanoid") == nil then -- we make sure it's not a player tocuhed
		if  hit ~= nil and hit.Name == "MaintPanel" then
			MaintenanceEvent:FireServer(game.Players.LocalPlayer)
		end
	end 
end)

Server/PanelScript:

function receive(player)
	warn(player)
	--do stuff
end

MaintFire.OnServerEvent:Connect(receive())

Is there any way to make this work without BindableEvents?

4 comments

0

Panel script?

0

the script inside the panel that its being touched.

0

What help do you need from your script?

0

I want to be able to use a localscript inside the tool, however the :touched function doesn't work.

1 answer

✓ Accepted answer

As long as your RBXScriptConnection is written in a Server Script, you should be fine. Avoid using it in LocalScripts alongside Remotes, that's asking for exploiters.

I wouldn't be able to make out a difference between using it in a LocalScript and server script, unless UserInputService is being used alongside it.

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