this script is for making a gui appear, music play, and camera change when you touch a part. that part works, but i think it works too many times as when you touch the part, it appears for a second, then crashes the game/studio..
i think the problem is the debounce, and it is not working correctly. i get no errors from this script either, but any help is really appreciated.
debounce = false function onTouched(hit) local player = game.Players:GetPlayerFromCharacter(hit.Parent) if player and debounce == false then debounce = true player:WaitForChild("PlayerGui").Credits.Frame.Visible = true end local Camera = game.workspace.CurrentCamera workspace.ramp.Touched:Connect(onTouched) Camera.CameraType = "Scriptable" Camera.CFrame = game.workspace.CamPart2.CFrame end local debounce = false Music = script.credits STAR = game.SoundService.STAR workspace.ramp.Touched:connect(function(hit) if not hit.Parent:FindFirstChild("Humanoid") then return end debounce = true Music:Play() STAR:Pause() workspace.ramp.Touched:Connect(onTouched) debounce = true game.Workspace.ramp.CanCollide = false game.Workspace.mainwall.CanCollide = true end)
EDIT: Shortened my plea for help
Simply put a wait()
debounce = false wait() function onTouched(hit) local player = game.Players:GetPlayerFromCharacter(hit.Parent) if player and debounce == false then debounce = true player:WaitForChild("PlayerGui").Credits.Frame.Visible = true end wait() local Camera = game.workspace.CurrentCamera workspace.ramp.Touched:Connect(onTouched) Camera.CameraType = "Scriptable" Camera.CFrame = game.workspace.CamPart2.CFrame end wait() local debounce = false Music = script.credits STAR = game.SoundService.STAR workspace.ramp.Touched:connect(function(hit) if not hit.Parent:FindFirstChild("Humanoid") then return end debounce = true Music:Play() STAR:Pause() workspace.ramp.Touched:Connect(onTouched) debounce = true game.Workspace.ramp.CanCollide = false game.Workspace.mainwall.CanCollide = true end)