Player > ClickDetector > Part (candle) See description

Is there any experienced programmers out there who can help me?

So basically I made a candle and when the player joins the game I want the player to touch the candle and when it touches the candle I want it to show a pop-up message about the candle. I’m not really a trained programmer but if anybody can find a solution to this then that will be helpful. Here is the candle.

The best way to do this is through a RemoteEvent. You would need to create a RemoteEvent in ReplicatedStorage, then add a script with a Touch event in the candle. It would look something like this:

script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then -- checks if the thing that touched the candle has a humanoid. if it does, it is most likely a player
		local player = game.Players:GetPlayerFromCharacter(hit.Parent) -- gets the player from its character
		if player then -- checks if the player exists
			game:GetService("ReplicatedStorage"):FindFirstChild(EventNameHere):FireClient(player) -- fires the event to the client
		end
	end
end)

After you’ve done this, you need to catch the event in a LocalScript. You could do this:

game:GetService("ReplicatedStorage"):FindFirstChild(EventNameHere).OnClientEvent:Connect(function() -- catch the event
	-- make it do stuff
end)

Change all “EventNameHere” to your event name.

I hope this helped, if you have any issues don’t hesitate to ask for help!

4 Likes

Alright, I’ll have a go now and review the results.

Scripting Support is not a venue to ask for code. In the future, please ensure that you attempt to use the resources and tutorials available to try and solve your issue. If you cannot figure it out, you can post a thread regarding your issue and provide the attempts and/or current code you’re working with.

In terms of this problem, you can actually solve it all in a LocalScript contrary to Rezault’s solution. His solution suggests handling touch detection from the server, which will result in communicatory delays that are native to client-server interaction. To minimise delays, you can easily handle everything from a LocalScript. You don’t need the server to use any memory doing this, even though the memory take up from this evaluation is fairly negligible.

What you will need to do:

  • Create a LocalScript, preferably in StarterCharacterScripts, that handles examination interaction (or whatever it is that your intended system needs to accomplish)
  • Connect to Torso.Touched; upon touch, perform actions on the client-side that prompts information about the object you have

There are various articles on the Developer Hub that you can read up for information on APIs. Here are some specifically you should consider, as they are relevant to your use case:

Feel free to search some more if you need more information.

4 Likes