Okay, so I'm making a game based off of Cookie Clicker, so I require a cookie that needs to be clicked that gives you a 'Click' every time the button is clicked.
My script so far is this:
local cookie = script.Parent cookie.MouseButton1Click:Connect(function() game.Players.LocalPlayer.leaderstats.Clicks = game.Players.LocalPlayer.leaderstats.Clicks + 1 end)
It's in a local script, and all lines of the script are correct. My output error is:
Players.dxrrevn.PlayerGui.ScreenGui.MAINBG.Frame.ImageButton.AddCookieScript:4: attempt to perform arithmetic (add) on Instance and number - Client - AddCookieScript:4>
I'm unsure on how to rectify this problem, any help would be greatly appreciated.
Thanks, dxrrevn
Well first off, if your using a Server Script (The normal one), change it to a local script as localplayer doesn't work in server scripts and place it under the imagelabel.
Then type this:
local cookie = script.Parent local Player = game.Players.LocalPlayer
cookie.MouseButton1Click:Connect(function() Player.leaderstats.Clicks.Value = Player.leaderstats.Click.Value + 1 end)
you didn't add ".Value" after "Clicks" so you're just changing the leaderstats name instead of its value. This should work, and if it doesn't please reply and I will do it myself
localscript:
local addcookie = game.ReplicatedStorage.AddCookie -- creat remoteevent named AddCookie local cookie = script.Parent local Player = game.Players.LocalPlayer cookie.MouseButton1Click:Connect(function() addcookie:FireServer() end)
serverscript:
local addcookie = game.ReplicatedStorage.AddCookie addcookie.OnServerEvent:Connect(function(player) player.leaderstats.Clicks = player.leaderstats.Clicks + 1 end)
this code will fire from client to server because when you use local script it didnt save your click number . This code will work perfect.