Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

ClickDetector Code to add cash when a part is clicked?

Asked by 6 years ago

I have this code which changes the colour of a brick when clicked which works. How do I edit so that it adds cash to a players leaderstats when clicked.

My clickdetector brickcolour code:

game.Workspace.MyClickDetectorEvent.OnServerEvent:Connect(function() script.Parent.Parent.MyPart.BrickColor = BrickColor.Random() end)

Do i change the script.Parent.MyPart BrickColor output to make it adds cash to my leaderboard instead of changing the bricks colour?

I already have a leaderboard in my game with stats called "Cash" so do I have to type FindFirstChild Cash or something...

Thank You and Help is Appreciated

0
Try a cash.Value = cash.Value + (1) TiredMelon 405 — 6y

2 answers

Log in to vote
0
Answered by 6 years ago
workspace.MyClickDetectorEvent.OnServerEvent:connect(function(plr)
    plr.leaderstats.Cash.Value = plr.leaderstats.Cash.Value
end)

OnServerEvent automatically passes the player as an argument so you can use that to navigate to leaderstats then cash and manipulate it there

Ad
Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

Try This:

local credit = true
if credit == false then return end
if credit = true then
script.Parent.OnClicked:connect(function(Onclicked)

game.players.localplayer.leaderstats.Cash.Value  game.players.localplayer.leaderstats.Cash.Value + 500
end)
end
--Thank You jamiethegreatQ777 For Making This Script For Aspiringstar346
script.Parent.ClickDetector


If anything Is Wrong (Wich There Wont Be) Message Me On Discord jamiethegreatQ777_Z#0618

Answer this question