Raycast stops working after a while?
03 | game.Players.PlayerAdded:Connect( function (plr) |
04 | plr.CharacterAdded:Connect( function (chr) |
05 | local HumanoidRP = chr:WaitForChild( "HumanoidRootPart" ) |
07 | local newRay = Ray.new(HumanoidRP.CFrame.p, Vector 3. new( 0 ,- 1 , 0 ).unit * 10 ) |
08 | local Hit = game:GetService( "Workspace" ):FindPartOnRay(newRay, chr) |
10 | shared.hitPart = Hit.Name |
12 | if shared.hitPart = = "ShipTeleportPad" then |
13 | game.ReplicatedStorage.TeleportOn:FireClient(plr) |
15 | game.ReplicatedStorage.TeleportOff:FireClient(plr) |
17 | if shared.hitPart = = "DesertBaseplate" then |
18 | if area = = "lobby" or area = = "jungle" or area = = nil then |
20 | while area = = "desert" do |
21 | game.ReplicatedStorage.Desert:FireClient(plr) |
26 | if shared.hitPart = = "shipraycast" or shared.hitPart = = "GlassFloor" then |
28 | if area = = nil or area = = "desert" or area = = "jungle" then |
29 | game.ReplicatedStorage.Lobby:FireClient(plr) |
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?