Hey there! I am probably the most inexperienced person on these forums but I figured I’d ask a few questions with a project I’m going to try out. I am making a simulator, but it isn’t based on a tool that you click.
The basics is you could click anywhere and you would perform an action which would give you “points”. The thing is, all the tutorials out there are based off like weightlifting sim where you need to hold something. My question is: would I just make the tool invisible or is there something else I can do?
Again as I am very new any help would be appreciated. Thank again!
You don’t need a Tool in order to utilize the Mouse. After getting the mouse, you can use the Button1Down event to run a function every time the player clicks.
You should use a Remote Event to communicate between the client (which will handle when the mouse is clicked) and the server (which will handle [safely] giving the player points, etc. for clicking the mouse.
More about Remote Events here.
Here’s a simple script lays out how I personally would approach this concept. This would be a LocalScript inside StarterPlayerScripts:
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
-- This assumes you have a RemoteEvent named "MouseEvent" as a direct child of ReplicatedStorage
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local mouseEvent = ReplicatedStorage:WaitForChild("MouseEvent")
local function performAction()
print("The player clicked the mouse! Let's give them points on the server to be safe!")
mouseEvent:FireServer() -- fires to the server, handle this request in a Script within ServerScriptService or something.
end
mouse.Button1Down:Connect(performAction)
On the server-end, you should create a Folder inside each Player upon joining. Call this folder “leaderstats” (all lowercase, very important) and parent it to the Player. Within your leaderstats folder, create the Values you want to show up on your leaderboard (Points, Money, etc.) More about Leaderboards here.
When your Remote Event is fired from the client to the server, you can get information about the passed in player, such as their current Points and so on. You can manipulate these values, and since it’s now being changed on the server (not locally), the effects will be replicated to every client, very good!
This post got kind of long, but hopefully it gives a rough outline of how this type of simulator would end up looking code-wise! Hope this helps, let me know if you have any questions!