Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Can anyone explain me how i use this function?

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.

1 comment

0

Would you like it to show up for only the client or the whole server when someone presses the lever?

2 answers

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)

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.