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

Trying to make a script where the screen fades to black on click, but it isn't working; any help?

Asked by 4 years ago

I'm trying to make a script where if you click on a door, the screen will fade to black, and the player will be teleported to the set coordinates, to the screen fading back up again. For some reason, it only teleports me a second after clicking on it, without any of the fading or anything. Just need help with figuring this one out please.

script.Parent.ClickDetector.MouseClick:Connect(function(player)

    local char = player.Character
    local gui = game.StarterGui.ScreenGui.FrameDark

    gui.BackgroundTransparency = 0.9
    wait(0.1)
    gui.BackgroundTransparency = 0.8
    wait(0.1)
    gui.BackgroundTransparency = 0.7
    wait(0.1)
    gui.BackgroundTransparency = 0.6
    wait(0.1)
    gui.BackgroundTransparency = 0.5
    wait(0.1)
    gui.BackgroundTransparency = 0.4
    wait(0.1)
    gui.BackgroundTransparency = 0.3
    wait(0.1)
    gui.BackgroundTransparency = 0.2
    wait(0.1)
    gui.BackgroundTransparency = 0.1
    wait(0.1)
    gui.BackgroundTransparency = 0
    wait(0.1)
    char.HumanoidRootPart.CFrame = CFrame.new(-10.9, 1.75, 50.5)
    wait(0.1)
    gui.BackgroundTransparency = 0
    wait(0.1)
    gui.BackgroundTransparency = 0.1
    wait(0.1)
    gui.BackgroundTransparency = 0.2
    wait(0.1)
    gui.BackgroundTransparency = 0.3
    wait(0.1)
    gui.BackgroundTransparency = 0.4
    wait(0.1)
    gui.BackgroundTransparency = 0.5
    wait(0.1)
    gui.BackgroundTransparency = 0.6
    wait(0.1)
    gui.BackgroundTransparency = 0.7
    wait(0.1)
    gui.BackgroundTransparency = 0.8
    wait(0.1)
    gui.BackgroundTransparency = 0.9
    wait(0.1)
    gui.BackgroundTransparency = 1
    wait(0.1)


end)

(Also, any tips to shorten this script would be greatly appreciated)

1 answer

Log in to vote
-1
Answered by
Robowon1 323 Moderation Voter
4 years ago
script.Parent.ClickDetector.MouseClick:connect(function(char)
local plr = game.Players:FindFirstChild(char.Name)
for i = 1,0,-0.1 do
wait()
plr.PlayerGui.ScreenGui.FrameDark.Transparency = i
end
end)
0
-1 for using misleading identifiers (char points to the player, NOT the character), for going back to game.Players to find the player, when you can use the variable directly, for not explaining, and for messy code in general. Where are your indents? programmerHere 371 — 4y
Ad

Answer this question