Hello, devs! I am having an issue with a script in my game currently. It is a script which chooses a video to display when the timer counts down to 0. I used a tutorial by TheDevKing to help me achieve the cooldown system. However, in Studio, when 0 is reached, it hangs and I have to close Studio and open it again. I tested the game on the Roblox Client and it acts a bit differently. It actually plays the video selected but after a while, kicks you from the game claiming you got disconnected on PC and mobile. Here is the script. Thanks for any help!
local shortId = 0
local chosenShort = ""
local randomNum = math.random(1, 4)
if randomNum == 1 then
shortId = game.ReplicatedStorage.Shorts["Eat!"].Video
chosenShort = game.ReplicatedStorage.Shorts["Eat!"]
end
if randomNum == 2 then
shortId = game.ReplicatedStorage.Shorts["News Station"].Video
chosenShort = game.ReplicatedStorage.Shorts["News Station"]
end
if randomNum == 3 then
shortId = game.ReplicatedStorage.Shorts["Lagoon Cliff Waterfall"].Video
chosenShort = game.ReplicatedStorage.Shorts["Lagoon Cliff Waterfall"]
end
if randomNum == 4 then
shortId = game.ReplicatedStorage.Shorts["Fight Loop"].Video
chosenShort = game.ReplicatedStorage.Shorts["Fight Loop"]
end
local InSessionLength = chosenShort.TimeLength
local IntermissionLength = 70
local InSession = game.ReplicatedStorage.Room1InShort
local Status = game.ReplicatedStorage.Room1Status
local function timer()
for i = IntermissionLength, 0, -1 do
InSession.Value = false
wait(1)
Status.Value = "Room 1 Intermission: ".. i .." seconds left to enter!"
end
for i = InSessionLength, 0, -1 do
InSession.Value = true
wait(1)
Status.Value = "Room 1 Watching Short!"
end
end
local maxval = script.Parent.MaxAllowed
local space = 0
script.Parent.ProximityPrompt.ActionText = "Enter - "..space.."/"..maxval.Value
spawn(timer)
script.Parent.ProximityPrompt.Triggered:Connect(function(player)
if space < 10 then
player.Tickets.Value = player.Tickets.Value - 1
space = space + 1
player.Character.HumanoidRootPart.Position = Vector3.new(-187.076, -6.307, -23.176)
script.Parent.ProximityPrompt.ActionText = "Enter - "..space.."/"..maxval.Value
end
end)
InSession.Changed:Connect(function()
if InSession.Value == true then
game.Workspace.MovieTheater.Room1Entrance.EnterPrompt.ProximityPrompt.Enabled = false
game.Workspace.Part.SurfaceGui.VideoFrame.Video = shortId
game.Workspace.Part.SurfaceGui.VideoFrame.Playing = true
game.Workspace.Part.SurfaceGui.VideoFrame.Played:Connect(function()
InSession.Value = false
game.Workspace.Part.SurfaceGui.VideoFrame.Video = ""
end)
else
game.Workspace.MovieTheater.Room1Entrance.EnterPrompt.ProximityPrompt.Enabled = true
space = 0
script.Parent.ProximityPrompt.ActionText = "Enter - "..space.."/"..maxval.Value
end
end)