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

Why does this only work once?

Im making a script that makes your screen dark when you walk into a room and makes your screen bright when your outside. It works fine, but for some reason it only works once help pls?

Main = script.Parent
Mask = Main.Mask
Mask1 = Main.Mask1
player = game.Players.LocalPlayer
mouse = player:GetMouse()



while wait() do
local ray = Ray.new(
                Vector3.new(player.Character.Head.Position),
                Vector3.new(0, 900, 0)
            )
local part, endPoint = Workspace:FindPartOnRay(ray)


if part then
	Mask.BackgroundTransparency = 1
	Mask1.BackgroundTransparency = 0.8
	elseif not part then
	Mask.BackgroundTransparency = 0.8
	Mask1.BackgroundTransparency = 1
end

end

2 comments

0

Is there any errors?

0

no, I found out that it is becase parts in the Player dont change position, So the reason its happening once is because the ray is only happening in one spot, which is the spot the player spawns in.

1 answer

Try that, it should work.

Main = script.Parent
Mask = Main.Mask
Mask1 = Main.Mask1
player = game.Players.LocalPlayer
mouse = player:GetMouse()


while true do
while wait() do
local ray = Ray.new(
                Vector3.new(player.Character.Head.Position),
                Vector3.new(0, 900, 0)
            )
local part, endPoint = Workspace:FindPartOnRay(ray)


if part then
    Mask.BackgroundTransparency = 1
    Mask1.BackgroundTransparency = 0.8
    elseif not part then
    Mask.BackgroundTransparency = 0.8
    Mask1.BackgroundTransparency = 1
end
end
end

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