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:
1 | local cookie = script.Parent |
2 |
3 | cookie.MouseButton 1 Click:Connect( function () |
4 | game.Players.LocalPlayer.leaderstats.Clicks = game.Players.LocalPlayer.leaderstats.Clicks + 1 |
5 | 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:
1 | local addcookie = game.ReplicatedStorage.AddCookie -- creat remoteevent named AddCookie |
2 | local cookie = script.Parent |
3 | local Player = game.Players.LocalPlayer |
4 | cookie.MouseButton 1 Click:Connect( function () |
5 | addcookie:FireServer() |
6 | end ) |
serverscript:
1 | local addcookie = game.ReplicatedStorage.AddCookie |
2 | addcookie.OnServerEvent:Connect( function (player) |
3 | player.leaderstats.Clicks = player.leaderstats.Clicks + 1 |
4 | 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.