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
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
local sp = script.Parent
local Players = game:GetService("Players")
local player = Players.LocalPlayer
sp.Parent = player
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
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)
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.
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?
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).