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

How do I call a function?

Asked by
Kitorari 266 Moderation Voter
7 years ago
Edited 7 years ago
score = 0

workspace.PartSensor.Touched:connect(function(Otherpart)
    if Otherpart.Name == 'Bowling Ball' then
    youpunk() -- The function i'm trying to call, which will begin the scan.
    wait(2)
    print(score)
    end
end)

For some strange reason, I cannot get youpunk() to be called, and it ends up printing the score as 0, even though it should be scanning, It might be this code that messed up but

if workspace.PartScoreBoard.SurfaceGui.Frame.Pin1.BackgroundColor3 == Color3.new(1, 0, 1) then
    score = score + 10
    wait(0.2)
    else
    end

I don't think anything is wrong there, I repeat the script above nine times with 9 different "Pin1-Pin9" Background colors..

score = 0

workspace.PartSensor.Touched:connect(function(Otherpart)
    if Otherpart.Name == 'Bowling Ball' then
    youpunk()
    wait(2)
    print(score)
    end
end)


function youpunk()
    if workspace.PartScoreBoard.SurfaceGui.Frame.Pin1.BackgroundColor3 == Color3.new(1, 0, 1) then
    score = score + 10
    wait(0.2)
    else
    end
    if workspace.PartScoreBoard.SurfaceGui.Frame.Pin2.BackgroundColor3 == Color3.new(1, 0, 1) then
    score = score + 10
    wait(0.2)
    else
    end
    if workspace.PartScoreBoard.SurfaceGui.Frame.Pin3.BackgroundColor3 == Color3.new(1, 0, 1) then
    score = score + 10
    wait(0.2)
    else
    end
    if workspace.PartScoreBoard.SurfaceGui.Frame.Pin4.BackgroundColor3 == Color3.new(1, 0, 1) then
    score = score + 10
    wait(0.2)
    else
    end
    if workspace.PartScoreBoard.SurfaceGui.Frame.Pin5.BackgroundColor3 == Color3.new(1, 0, 1) then
    score = score + 10
    wait(0.2)
    else
    end
    if workspace.PartScoreBoard.SurfaceGui.Frame.Pin6.BackgroundColor3 == Color3.new(1, 0, 1) then
    score = score + 10
    wait(0.2)
    else
    end
    if workspace.PartScoreBoard.SurfaceGui.Frame.Pin7.BackgroundColor3 == Color3.new(1, 0, 1) then
    score = score + 10
    wait(0.2)
    else
    end
    if workspace.PartScoreBoard.SurfaceGui.Frame.Pin8.BackgroundColor3 == Color3.new(1, 0, 1) then
    score = score + 10
    wait(0.2)
    else
    end
    if workspace.PartScoreBoard.SurfaceGui.Frame.Pin9.BackgroundColor3 == Color3.new(1, 0, 1) then
    score = score + 10
    wait(0.2)
    else
    end
end

Assistance would be great!

0
You'd be much better off with .changed events. And you could put all the pins in a loop and have your whole script in probably less than 25 lines. GoldenPhysics 474 — 7y

2 answers

Log in to vote
1
Answered by 7 years ago
Edited 7 years ago

You are calling the function correctly. It's possible the problem lies within the code for youpunk, also you don't need to add else to every if statement unless you intend to do something if what you are checking is false. If it's making it to print(score) and score is still 0 then it would seem to me the youpunk() function ran without a problem however all of the if states did not do what you intended. To check this you can add prints for the elses in your if statements to see if what you are checking is true or not, and thus if it's adding to the score like you want it to.

Example:

if workspace.PartScoreBoard.SurfaceGui.Frame.Pin9.BackgroundColor3 == Color3.new(1, 0, 1) then
     score = score + 10
     wait(0.2)
 else
    print("Hey we didn't add to the score because our check was false")
 end
Ad
Log in to vote
1
Answered by 7 years ago
Edited 7 years ago

Try putting return after all the elses, example:

if then
    --something
else
    return
end

And are you sure the function "youpunk" is created before everything else?

I am not even sure if "Pin1, Pin2, Pin3, Pin4, Pin5, Pin6, Pin7, Pin8 and Pin9" is a thing in a frame?

Answer this question