"Clicks" not increasing

So, I’ve been trying to make a clicker for the past two weeks (I learned from a tutorial). But I ended up runinng into the same problem, every time: clicks not going up. No matter how many edits I made trying to figure it out, trying to remove all the errors, I failed every time, cuz I’m new to this scripting thing. I’m now a DevForum member, so now you guys can help!

These scripts are what I’m at now after going through a downward spiral of desperation. I was rushing a looooooooottt :upside_down_face:

local Players = game:GetService("Players")
local player = Players.LocalPlayer
local sp = game:GetService("StarterPlayer")
local cd = sp:FindFirstChildWhichIsA("Script")
local clickEvent = cd:FindFirstChild("clickEvent")

clickEvent.OnServerEvent(function(player)
	local leaderstats = player.leaderstats
	local multiplier = player.multiplier
	local clicks = player:FindFirstDescendant("clicks")
	print("+1")
	clicks.Value = clicks.Value + (1 + multiplier.Value)
	leaderstats.Clicks.Value = clicks
end)
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local mouse = player:GetMouse()
local clickEvent = script:FindFirstChild("clickEvent")

local function onMouseClick()
	clickEvent:FireServer(player)
end

mouse.Button1Down:Connect(onMouseClick)

and this last one imo is pretty dumb, so idc :sweat_smile:

local sp = script.Parent

local Players = game:GetService("Players")
local player = Players.LocalPlayer

sp.Parent = player
5 Likes

I am not too sure that you can access StarterPlayer with a regular script, I would store the remoteEvent in ReplicatedStorage where it can be accessed by both the server and the client and see if it works

3 Likes

Don’t send the player argument in the LocalScript. The server already knows what player is sending the event.

What exactly should I change? As in, the new script?

local Players = game:GetService("Players")
local player = Players.LocalPlayer
local mouse = player:GetMouse()
local clickEvent = script:FindFirstChild("clickEvent")

local function onMouseClick()
	clickEvent:FireServer() -- omit player
end

mouse.Button1Down:Connect(onMouseClick)
1 Like

There’s also something wrong in your server script.

clickEvent.OnServerEvent:Connect(function(player) -- add :Connect
	local leaderstats = player.leaderstats
	local multiplier = player.multiplier
	local clicks = player:FindFirstDescendant("clicks")
	print("+1")
	clicks.Value = clicks.Value + (1 + multiplier.Value)
	leaderstats.Clicks.Value = clicks
end)
1 Like

I don’t have any LocalScripts.

I also just omitted “player” like @Trafficboy05 said, but I still have this error.

“ServerScriptService.clickReceiver:5: attempt to call a RBXScriptSignal value”

You can only access LocalPlayer in a LocalScript

Wow, how could I forget “connect”?

me stoopid :face_with_diagonal_mouth: :sweat_smile:

Okay, here’s my new scripts thus far:

local Players = game:GetService("Players")
local player = Players.LocalPlayer
local clickEvent = game.ReplicatedStorage.remoteEvents.click

clickEvent.OnServerEvent:Connect(function()
	local leaderstats = player.leaderstats
	local multiplier = player.multiplier
	local clicks = player:FindFirstDescendant("clicks")
	print("+1")
	clicks.Value = clicks.Value + (1 + multiplier.Value)
	leaderstats.Clicks.Value = clicks
end)
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local mouse = player:GetMouse()
local clickEvent = game.ReplicatedStorage.remoteEvents.click

local function onMouseClick()
	clickEvent:FireServer()
end

mouse.Button1Down:Connect(onMouseClick)
local Players = game:GetService("Players")
local clickEvent = game.ReplicatedStorage.remoteEvents.click

clickEvent.OnServerEvent:Connect(function(player) -- readd player
	local leaderstats = player.leaderstats
	local multiplier = player.multiplier
	local clicks = player:FindFirstChild("clicks",true) -- :FindFirstDescendant() is currently disabled.
	print("+1")
	clicks.Value = clicks.Value + (1 + multiplier.Value)
	leaderstats.Clicks.Value = clicks
end)

OnServerEvent will not work in a LocalScript, same with LocalPlayer. This should be a regular Script.
The OnServerEvent RBXScriptConnection, when fired, will give you the player who triggered the connection, or in this case, fired an event.

Also, why are there two clicks values? You could just use one.

1 Like

Two “clicks” values? Where’s the second?

1 Like

Wait, my bad. I misread the script.

You’re just setting the value twice, which you don’t need to do.

edit: Also accidentally left player = Players.LocalPlayer in the script, oops

Can I see where you put each of your scripts?

The intention of

clicks.Value = clicks.Value + (1 + multiplier.Value)
leaderstats.Clicks.Value = clicks

was to update it on the leaderboard.
Well, you guys know more about scripting than me, so, I’ll still listen for tips.

1 Like

It should automatically update on the leaderboard, because you set it already and the clicks variable is a reference to leaderstats.Clicks

Also, is “clicks” in :FindFirstChild("clicks",true) correctly capitalized when declaring variable “clicks”?

1 Like

Also note that you can just do clicks.Value += 1 + multiplier.Value
Another thing is that it is a multiplier right? So wouldn’t you do 1 * multiplier.Value? And since it is a 1 you can just do multiplier.Value?

The first script (see top) is named “clickReceiver”, where when the event is fired, the player earns clicks.

The second is “clickDetect”, which is supposed to detect the input (left mouse button) and fire the event, which cR is supposed to get

And the the third is a result of me parenting random crap a bunch of times trying to find a solution in a Lua haystack.

Nonono I meant screenshot the explorer and show where you placed each script. That way we know what kind of scripts they are and if they will actually run (most importantly the former).

Well, the multiplier is set to 1, so I’ll be revising my code to see how I can make it work in a different way.