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

onClicked function (very basic, pls help)?

Asked by 6 years ago

literally just started scripting, very basic, pls help

output is always "it's not" even though the transparency of the parent IS 0

yeet = game.Workspace.Part

function onClicked ()
    if script.Parent.Transparency == '0' then
        script.Parent.Properties.BrickColor = 'Really red'
    else
        print("it's not")
    end
end

script.Parent.ClickDetector.MouseClick:connect(onClicked)
0
its not '0'. It's just 0. 0 is not a string but a numerical value. You only put "" for texts. Ex. "partName" Axceed_Xlr 380 — 6y

2 answers

Log in to vote
0
Answered by 6 years ago

When addressing things like Transparency, you don't actually need to address the "properties."

You did: script.Parent.Properties.BrickColor = 'Really red'

When you should do

script.Parent.BrickColor = 'Really red'

But, you forgot one thing.

local yeet = game.Workspace.Part --don't forget the local!

function onClicked ()
    if script.Parent.Transparency == '0' then
        script.Parent.Properties.BrickColor = BrickColor.new('Really red') --You need to add the "BrickColor.new()"
    else
        warn("it's not") --Tip: You can change the print to "Warn", and it will appear yellow in the output. Nothing important, just easier to read.
    end
end

script.Parent.ClickDetector.MouseClick:connect(onClicked)

You forgot the BrickColor.new()

If this helped, then please accept the answer. Thanks!

0
for some reason it's still outputting "it's not" TwistedGabe 2 — 6y
0
Erm, you forgot to address the primary issue, with it always failing the first conditional statement. Shawnyg 4330 — 6y
0
Yes, I overlooked that. The problem is that you made the '0' a string, which it is not. Remove the " ' ' " around the 0 for it to work MakeYourEscape 334 — 6y
Ad
Log in to vote
0
Answered by
Shawnyg 4330 Trusted Badge of Merit Snack Break Moderation Voter Community Moderator
6 years ago

Glad you've taken an interest in scripting! You're very close to solving this problem. Transparency accepts a float value, which is essentially a number. When you were attempting to compare it against a string, it would always return false since a number isn't a string. To fix that problem, you need to remove the quotes, and it'll become a number! I also noticed another problem. When you were attempting to change the BrickColor, you do not need to state 'Properties'. Think of it like Transparency, you can directly go to it. When setting a BrickColor of a part, it takes a BrickColor value, and in this case you can use BrickColor.new(). So:

yeet = game.Workspace.Part

function onClicked ()
    if script.Parent.Transparency == 0 then
        script.Parent.BrickColor = BrickColor.new('Really red')
    else
        print("it's not")
    end
end

script.Parent.ClickDetector.MouseClick:Connect(onClicked) -- Tiny edit here! 'connect' is deprecated (no longer supported), so be sure to use 'Connect'!

Answer this question