Hi I was making this script and I was wonder why this didn't work. Also it didn't have any output errors and it is in a local script. Can you help me with this script problem?
function OnClick() local plr = game.Players.LocalPlayer if plr:FindFirstChild("leaderstats") ~= nil then local clicks = plr:FindFirstChild("leaderstats"):FindFirstChild("Cow Clicks") if (clicks ~= nil) then clicks.Value = clicks.Value + 1 script.Parent.Sound:Play() end else print("leaderstats not found") end end script.Parent.ClickDetector.MouseClick:connect(OnClick)
You don't need a LocalScript for this, neither should you use one. The ClickDetector's MouseClick event passes the player that clicks as an argument to its connected function
function OnClick(theguythatclicked) --Get that tabbing under control. --One function, one conditional statement, --one loop, etc. gets one tab. --You should let the IDE do it for --you for the most part. local clicks = theguythatclicked:FindFirstChild("leaderstats"):FindFirstChild("Cow Clicks") if clicks then clicks.Value = clicks.Value + 1 script.Parent.Sound:Play() end end script.Parent.ClickDetector.MouseClick:connect(OnClick) --Event passing player to function