"Clicks" not increasing

It wont work. The error specifically states that OP is indexing “nil” with leaderstats, which means “player” is nil. We have to understand the context in order to figure out what is going wrong.

1 Like

wow, ok i think im caught up! did u use gnome codes tutorial? (seems random but bc i followed it and im making a clicking game i think i could help.) if so i can send u my code (his is kind of bad ngl)

1 Like

Send us the full script. (I’ve asked like so many times :|||||)

2 Likes

The OP did omit the player argument from the connection at one point, so I’m not sure if that’s the reason or if OP added it back.

Exactly why I’m asking for the script OP is using :sob:

  1. My multiplier is 1
  2. It’s sensing the clicks now, the error pops up upon clicking
  3. I’ve only tested the game in Roblox Studio
  4. Thanks, @xvortex_portals
  5. Here’s the full clickReceiver script now:
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local clickEvent = game.ReplicatedStorage.remoteEvents.click

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

But now the error is “attempt to index nil with ‘WaitForChild’” instead of “with ‘leaderstats’”

1 Like

clickEvent.OnServerEvent:Connect(function(player) -- readd player You omitted player, again

1 Like

Remove this line: local player = Players.LocalPlayer

I’ve deleted the line, but now the clicks still aren’t going up

@Optical4937

please let me know if u did!

Did you re-add the player argument in the connection?

Actually, here’s the script.

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

clickEvent.OnServerEvent:Connect(function(player) -- add player argument
	local leaderstats = player:WaitForChild("leaderstats")
	local multiplier = player:WaitForChild("multiplier")
	local clicks = player:FindFirstChild("Clicks",true) -- FindFirstDescendant is not enabled
	print("+1")
	clicks.Value = clicks.Value + (multiplier.Value)
    -- clicks is a reference to leaderstats.Clicks!
end)

aright im going to bed cya tmrw

I used this guy’s tutorial: DevBlox

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

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

I’m getting "infinite yield possible on ‘Players.(playername):WaitForChild(“multiplier”)’

YES that’s right i used gnome code for my tower defense, so we are using the same script. one second

ive got to go to bed but if u haven’t fixed it by around 4:00 tmrw [EST] i think ill be back on

Is the multiplier object being created, or is it supposed to be capitalized? WaitForChild is case-sensitive, so is just about every other method.

1 Like

The multiplier is never created, it has its own script:

game.Players.PlayerAdded:Connect(function(player)
	local leaderstats = player:FindFirstChild("leaderstats")
	local multiplier = Instance.new("IntValue",player)
	multiplier.Name = "Multiplier"
	multiplier.Parent = player
	multiplier.Value = 1
end)

I also just realized I don’t need leaderstats if I’m not gonna use it

You can remove multiplier.Parent, because you’re already setting its parent in Instance.new("IntValue",player)

game.Players.PlayerAdded:Connect(function(player)
	local leaderstats = player:FindFirstChild("leaderstats")
	local multiplier = Instance.new("IntValue",player)
	multiplier.Name = "Multiplier"
	-- remove multiplier.Parent in favor of doing it in the Instance.new function
	multiplier.Value = 1
end)