Here is my script:
When I click the button, nothing happens. What am I doing wrong?
q=math.random[2-6] game.Players.PlayerAdded:connect(function(player) function onClicked() if script.Parent.Name==("Sell lemonade") then wait(.4) script.Parent.Name=("Selling on cup of lemonade..") wait(q) script.Parent.Name=("Someone has bought a cup of lemonade!") player.leaderstats["Maple Leaves"].Value = player.leaderstats["Maple Leaves"].Value + 4 wait(.2) script.Parent.Name=("Sell lemonade") end end script.Parent.ClickDetector.MouseClick:connect(onClicked) end)
First off, the numbers for math.random should be enclosed with Parenthesis, secondly, they should be separated with Commas or Semi-Colons, for Instance, q=math.random(2,6)
or q=math.random(2;6)
Another thing, I'd take the onClicked function out of the PlayerAdded event, put it maybe like this:
function onClicked() --Code end game.Players.PlayerAdded:connect(function(Player) --Code end)
thought that's just me.
Fourth, I'd remove the Parenthesis from the strings, I'm not sure whether that'd error or not...
Finally, You'd want to check to make sure everything is where it's supposed to be before running your code...
(Also, the MouseClick event from the ClickDetector returns the Player automatically)
It should look like this in my opinion
function onClicked(Player) local LS=Player:FindFirstChild("leaderstats") if not LS then return end local Stat=LS:FindFirstChild("Maple Leaves") if not Stat then return end if script.Parent.Name=="Sell Lemonade" then wait(.4) script.Parent.Name="Selling one cup of lemonade..") wait(q) script.Parent.Name="Someone has bought a cup of lemonade!" Stat.Value=Stat.Value+4 wait(.2) script.Parent.Name="Sell Lemonade" end end script.Parent.ClickDetector.MouseClick:connect(onClicked)