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

Hi.Script breaking for some reason?

Asked by 9 years ago

Here is the code.

function Click(Clicker)
 game.workspace.SpecialPartVictim.Transparency=0.1
    game.workspace.SpecialPartVictim2.Transparency=0.1
    game.workspace.SpecialPartVictim3.Transpareny=0.1
    game.workspace.SpecialPartVictim4.Transparency=0.1
    game.workspace.SpecialPartVictim5.Transparency=0.1
    game.workspace.SpecialPartVictim6.Transparency=0.5
wait (20)   
     game.workspace.SpecialPartVictim.Transparency=1.0
    game.workspace.SpecialPartVictim2.Transparency=1.0
    game.workspace.SpecialPartVictim3.Transpareny=1.0
    game.workspace.SpecialPartVictim4.Transparency=1.0
    game.workspace.SpecialPartVictim5.Transparency=1.0
    game.workspace.SpecialPartVictim6.Transparency=1.0

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


end


As you can see im trying to make something visible from being invisible and after 20 seconds make invisible again.

What is wrong with this script?

1 answer

Log in to vote
1
Answered by
Perci1 4988 Trusted Moderation Voter Community Moderator
9 years ago

Your main problem is that your function will never run, because it is never called and is never connected to an event.

It is never connected to an event because the connection line is inside the function, meaning that the connection line will never be read until the function runs, and the function will never run unless the connection line is read.

function func()
    --code
end
script.Parent.ClickDetector.MouseClick:connect(func) --connection is outside the function, so it will be read as soon as the game starts.

Your code is, however, still pretty ugly. It would be better to group all your parts in a Model, then use a for loop to loop through that model. Example of the loop;

--will make all the children in 'model' slightly transparent. 
for index, child in pairs(model:GetChildren()) do
    child.Transparency = 0.1
end
0
Sorry - just a beginner at this :/ hussaingold 10 — 9y
0
No need to be sorry... Perci1 4988 — 9y
Ad

Answer this question