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

What is wrong with this script?

Asked by 10 years ago

Please make your question title relevant to your question content. It should be a one-sentence summary in question form.

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)

0
No offense, but what ARE you doing correct? ForeverDev 155 — 10y
0
I'm trying, sorry if I made careless errors DrCylonide 158 — 10y
0
@ForeverDev Would you not shoot people down just because you think you're better than them? You were most likely like this when you just started... Muoshuu 580 — 10y

1 answer

Log in to vote
2
Answered by
Muoshuu 580 Moderation Voter
10 years ago

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)
Ad

Answer this question