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

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

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

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)

1 comment

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?

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