game.Players.PlayerAdded:connect(function(plr) local stats = Instance.new("IntValue") stats.Name = "leaderstats" stats.Parent = plr local clicks = Instance.new("IntValue", stats) clicks.Name = "Clicks" clicks.Value = 0 clicks.Parent = stats local level = Instance.new("IntValue", stats) level.Name = "Rank" level.Value = 0 level.Parent = stats end)
first script
function onClick() --where I want to put my variable end script.Parent.MouseClick:connect(onClick)
second script . . I'm trying to make a clickable object thaat when you click it, the variable "clicks" goes up
When you use the MouseClick
event, you can insert a parameter that tells you who clicked the object. In your onClick
function we can insert a variable called "player" into the parentheses.
function onClick(player) --where I want to put my variable end script.Parent.MouseClick:connect(onClick)
Now whenever the object is clicked the player who clicked it will be stored in the variable "player".
Since you have added a value (clicks value) into the player directly from the server, we can access that value without a wall blocking us. Since we already have the player who clicked the object, we can just change their clicks
variable in the function.
function onClick(player) player.leaderstats.clicks.Value = player.leaderstats.clicks.Value + 1 end script.Parent.MouseClick:connect(onClick)
(you can make clicks into a variable if you want) This should work! :D
MouseClick
returns the player who clicked.
function onClick(player) if player.leaderstats:FindFirstChild("Clicks") then local ClicksValue = player.leaderstats:FindFirstChild("Clicks").Value ClicksValue = ClicksValue + 1 -- you can change the amount it adds end end script.Parent.MouseClick:connect(onClick)