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

Why does this only work once?

Asked by 10 years ago

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

0
Is there any errors? lomo0987 250 — 10y
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. jbjgang2 37 — 10y

1 answer

Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

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
Ad

Answer this question