I am making a simulator and am trying to find a way to make it so when you click on the screen you get points instead of clicking a GUI or button. I have tried to use a gear for this but I am not sure how to make the gear invisible on the screen or if you even can. I’m not asking for a script I’m more asking for a way to go about doing this.
1 Like
use UserInputService to detect mouse button clicks from the client
Alternatively you can use the “mouse” object which can be accessed for any client from a local script, you can use its features in conjunction with remote events to send mouse data to the server. Here’s an example:
--LOCAL SCRIPT--
local players = game:GetService("Players")
local player = players.LocalPlayer or players.PlayerAdded:Wait()
local character = player.Character or player.CharacterAdded:Wait()
local mouse = player:GetMouse()
local storage = game:GetService("ReplicatedStorage")
local re = storage:WaitForChild("ClickEvent")
mouse.Button1Down:Connect(function() --event fires when mouse button is clicked
re:FireServer()
end)
--SERVER SCRIPT--
local players = game:GetService("Players")
local storage = game:GetService("ReplicatedStorage")
local re = storage:WaitForChild("ClickEvent")
players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local clicks = Instance.new("IntValue")
clicks.Name = "Clicks"
clicks.Value = 0
clicks.Parent = leaderstats
end)
re.OnServerEvent:Connect(function(player)
player.leaderstats.Clicks.Value += 1
end)
Organisation:
a.rbxl (26.7 KB)
This is a simple clicking game which increases the leaderboard stat “Clicks” by 1 each time a mouse click occurs.
1 Like