How to safely tell server what object was clicked on the client

Hello, I’ve recently been hyperaware of the power that exploiters can have and I have been trying to make my game as safe as possible. I want to send what model the client has clicked to the server, but I believe that using a remote event to pass the parameters would be unsafe as an exploiter could send a different model to the server. If anyone knows how I would do this in a safe manner that would be amazing. Thanks.

Extra info: I need to send what model was clicked so I can tween an object to that model from the server. I also need to know what level that model is because different leveled models give a different amount of coins.

1 Like

you can use click detectors (added in server) and use .Clicked() from server

Yes, but the game is a sim so that would be a lot of click detectors and I feel like there should be a more optimal way

alternatively you can use a tool and use .Activated() and get players mouse target via an event

You could use a RemoveEvent and send the object that the player clicked, and check on the server if the Client’s Character is within a certain distance using
:DistanceFromCharacter(object.Position).Magnitude <= 10(in studs).

1 Like
for _, clicky in pairs(game.Workspace:GetDescendants()) do
	if clicky:IsA("ClickDetector") and clicky.Name  == "ClickDetector" then -- remove clicky.name if needed
		clicky.MouseClick:Connect(function()
			-- action
		end)
	end
end

here is the action part i guess:

game.ReplicatedStorage:FireClient()

MAKE SURE TO RUN THIS ON A SERVERSCRIPT plus add a remoteevent in replicatedstorage

I will most likely be using this method as I feel like it’s the least impactful on performance and easy to work with. Thank you!

this isn’t a bad idea, but because I will be constantly spawning and deleting models I feel it would be performance heavy to run this script every time a new model is created

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.