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

Raycast stops working after a while?

Asked by 4 years ago
local area

game.Players.PlayerAdded:Connect(function(plr)
    plr.CharacterAdded:Connect(function(chr)
        local HumanoidRP = chr:WaitForChild("HumanoidRootPart")
        while wait(0.1) do
            local newRay = Ray.new(HumanoidRP.CFrame.p, Vector3.new(0,-1,0).unit * 10)
            local Hit = game:GetService("Workspace"):FindPartOnRay(newRay, chr)
            if Hit then
                shared.hitPart = Hit.Name
            end
            if shared.hitPart == "ShipTeleportPad" then
                game.ReplicatedStorage.TeleportOn:FireClient(plr)
            else
                game.ReplicatedStorage.TeleportOff:FireClient(plr)
            end
            if shared.hitPart == "DesertBaseplate" then
                if area == "lobby" or area == "jungle" or area == nil then
                    area = "desert"
                    while area == "desert" do
                        game.ReplicatedStorage.Desert:FireClient(plr)
                        wait(60)
                    end
                end
            end
            if shared.hitPart == "shipraycast" or shared.hitPart == "GlassFloor" then
                print(area)
                if area == nil or area == "desert" or area == "jungle" then
                    game.ReplicatedStorage.Lobby:FireClient(plr)
                    area = "lobby"
                end
            end
        end
    end)
end)

What this does is it uses a raycast from the player down to see what part they are standing on. The first if which senses for ShipTeleportPad brings up a gui to teleport to the desert. This comes up when you step on it, and you can teleport to the desert. THe next senses if your touching the desert baseplate, and if you are, then it will fire an event that will change the music and skybox. The third if statement senses if you touch the lobby floor, which will fire an event that changes the skybox and the music. When you join, lobby works fine. When you teleport, desert works fine. But when you teleport from the desert back to the lobby, the raycast stops working entirely, not changing the music or skybox back, and not opening the teleport gui. Can somebody help me?

0
Use a loop JesseSong 3916 — 4y
0
I did it says while area == "desert" do Swaggyguy229 7 — 4y
0
also, you see the print(area) in the lobby part section? It prints lobby when you spawn, but after going to the desert it doesn't print at all. Swaggyguy229 7 — 4y

Answer this question