"Clicks" not increasing

We’re back to square one. No more errors, but I keep getting the same warning with every click and the clicks still aren’t increasing.

Are you using a gui or a part that senses the click or just the screen?

The LocalScript senses clicking the screen

But I thought if clicks was nil, it wouldn’t show up on the leaderboard. But it does.

Did you remove leaderstats?

clickEvent.OnServerEvent:Connect(function(player)
	-- remove leaderstats
	local multiplier = player:WaitForChild("multiplier")
	local clicks = player:FindFirstDescendant("clicks",true)
	print("+1")
	clicks.Value = clicks.Value + (multiplier.Value)
end)

If this still hasn’t been solved, here’s code that’ll work:

Server Script:

local Players = game:GetService("Players")
local player = Players.LocalPlayer
local clickEvent = game.ReplicatedStorage:FindFirstChild("ClickEvent")

if not clickEvent then
	clickEvent = Instance.new('RemoteEvent')
	clickEvent.Name = 'ClickEvent'
	clickEvent.Parent = game.ReplicatedStorage
end


clickEvent.OnServerEvent:Connect(function(player)
	local leaderstats = player:FindFirstChild('leaderstats')
	if not leaderstats then print('no leaderstats found') return end
	local multiplier = player:FindFirstChild('Multiplier')
	local clicks = player:FindFirstChild("Clicks")
	local clicksleaderstat = leaderstats:FindFirstChild('Clicks')
	
	if not clicks or not clicksleaderstat or not multiplier then print('instances missing') return end
	print("+1")
	clicks.Value = clicks.Value + (1 + multiplier.Value)
	leaderstats.Clicks.Value = clicks.Value
end)

LocalScript

local Players = game:GetService("Players")
local player = Players.LocalPlayer
local mouse = player:GetMouse()
local clickEvent = game.ReplicatedStorage:WaitForChild('ClickEvent')

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

mouse.Button1Down:Connect(onMouseClick)

Hope this is what you’re looking for. :slight_smile:

1 Like

I got “instances missing”. I think we’re getting somewhere again!

It’s not increasing the clicks, even in Roblox

WAIT JUST A MINUTE

local clicks = leaderstats:FindFirstChild("Clicks") -- Turns out that
-- "clicks" was parented to leaderstats and not the player.
-- I did that because of how I normally add something to a leaderboard

-- Which means that clicks should be leaderstats:FindFirstChild("Clicks")
-- instead of player:FindFirstChild("Clicks")
-- because clicks isn't one of player's children (and
-- player doesn't have FindFirstDescendant.

so its all fixed now?

[gfgfhfgfgfgfggfgfgfggfgfg]

Yes, it is solved. I just needed to edit a line from the solution @WrollingYou gave me.

1 Like

Can you put a solution please?

See WrollingYou’s reply. Just needed to clear that up.

1 Like

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