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

Can anyone explain me how i use this function?

Asked by 3 years ago

So i tried making a Lever that when i click on the Hitbox (ClickDetector) that it will make 1 part transparent and the other one not so it looks like the lever is pulled.

I tired making a scirpt altough is suck at scripting.

i made this.

function 
game.Workspace.SwitchTrack1.HandlePart1.Transparency = 1
    else
game.Workspace.SwitchTrack2.HandlePart1.Transparency = 0

end
script.Parent.Show.Click.MouseClick:connect(act)

Anyone can help me with my script? Would be very appericiated.

0
Would you like it to show up for only the client or the whole server when someone presses the lever? LeedleLeeRocket 1257 — 3y

2 answers

Log in to vote
2
Answered by
2_MMZ 1059 Moderation Voter
3 years ago
Edited 3 years ago

So your problem is that you don't have a function for this script, it doesn't know what to do. So here's a fixed script for you.

function(act)
print("Lever was pulled.")
game.Workspace.SwitchTrack1.HandlePart1.Transparency = 1
game.Workspace.SwitchTrack2.HandlePart1.Transparency = 0
end
script.Parent.Show.Click.MouseClick:Connect(act)

Ad
Log in to vote
0
Answered by 3 years ago

Learn proper Lua before you even try scripting. A lot of your syntax is already wrong. Namely the if control sequence and how you declare a function.

Here's their official guide. https://www.lua.org/pil/contents.html

Here's the fixed script if you want.

local function LeverClicked()
    workspace.SwitchTrack1.HandlePart1.Transparency = 1 --make the first lever part invisible.
    workspace.SwitchTrack2.HandlePart1.Transparency = 0 --make the first lever part visible again.
end

script.Parent.Show.Click.MouseClick:connect(LeverClicked)

And in anonymous functions if you want.

script.Parent.Show.Click.MouseClick:connect(function ()
    workspace.SwitchTrack1.HandlePart1.Transparency = 1 --make the first lever part invisible.
    workspace.SwitchTrack2.HandlePart1.Transparency = 0 --make the first lever part visible again.
end)

Answer this question