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

Help With Button Script?

Asked by 8 years ago

i wanted the sail of my sailboat to apare on a click of a button something went wrong help me

function Onclicked(mouse)
    script.Parent.mouseButton1click = script.Parent.Parent.Parent.Sail.Transparency = 1
    end
    Onclicked (mouse)

2 answers

Log in to vote
1
Answered by
Reselim 35
8 years ago

You'd have to rewrite the button's script:

function Onclicked(mouse)

    script.Parent.Parent.Parent.Sail.Transparency = 1

end

script.Parent.MouseButton1Click:connect(Onclicked)

Basically, you'd connect the MouseButton1Click's part of the TextButton or ImageButton to a function, in which the function would be called every time the button is pressed.

0
Explain the code, it does not benefit the Asker by just pasting code. M39a9am3R 3210 — 8y
Ad
Log in to vote
1
Answered by 8 years ago

So that answer that Reselim did is correct, but he didn't explain lemme explain for you. When you write functions you ALWAYS need to call it or else it won't work! heres an example for a simple button script.

function:

function click()

code:

script.Parent.Visible = true

call the function

script.Parent.MouseButton1Click:connect(click)

as you see I put click in the parenthese. This means that you are talking about this function!

But there is two ways to call it 1.

script.Parent.MouseButton1Click(THE NAME OF FUNCTION)

or

script.Parent.MouseButton1Click:connect(function(click)

Your full script

function Onclicked(mouse)

    script.Parent.Parent.Parent.Sail.Transparency = 1

end

script.Parent.MouseButton1Click:connect(Onclicked)

OR

script.Parent.MouseButton1Click:connect(function(mouse)

    script.Parent.Parent.Parent.Sail.Transparency = 1

end

Both should work any more questions? Ask me!

0
Way better than mine. Reselim 35 — 8y

Answer this question